Ionic 无法加载控制器

ca1c2owp  于 2022-12-09  发布在  Ionic
关注(0)|答案(2)|浏览(249)

创建一个带电容器的离子5应用程序,我遇到了这个问题,似乎capacitor.config.json没有被加载。
这个问题是在我安装了@codetrix-studio/capacitor-google-auth之后出现的,在这个项目在android上运行之前。

{
  "appId": "com.luyou.clauncher",
  "appName": "c-launchpad",
  "bundledWebRuntime": false,
  "npmClient": "npm",
  "webDir": "www",
  "plugins": {
    "SplashScreen": {
      "launchShowDuration": 0
    },
    "GoogleAuth": {
      "scopes": [
        "profile",
        "email"
      ],
      "serverClientId": "xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com", // On my project I'm using the real server client id
      "forceCodeForRefreshToken": true
    }
  }
}

在Android Studio上,构建过程正常,但当您尝试打开应用程序时,它确实会崩溃,并显示以下信息:

D/Capacitor: Starting BridgeActivity
E/Capacitor: Unable to load capacitor.config.json. Run npx cap copy first
    java.io.FileNotFoundException: capacitor.config.json
        at android.content.res.AssetManager.nativeOpenAsset(Native Method)
        at android.content.res.AssetManager.open(AssetManager.java:874)
        at android.content.res.AssetManager.open(AssetManager.java:851)
        at com.getcapacitor.FileUtils.readFile(FileUtils.java:148)
        at com.getcapacitor.CapConfig.loadConfig(CapConfig.java:121)
        at com.getcapacitor.CapConfig.loadDefault(CapConfig.java:85)
        at com.getcapacitor.Bridge.<init>(Bridge.java:152)
        at com.getcapacitor.Bridge$Builder.create(Bridge.java:1160)
        at com.getcapacitor.BridgeActivity.load(BridgeActivity.java:73)
        at com.getcapacitor.BridgeActivity.init(BridgeActivity.java:54)
        at com.getcapacitor.BridgeActivity.init(BridgeActivity.java:37)
        at com.luyou.clauncher.MainActivity.onCreate(MainActivity.java:19)
        at android.app.Activity.performCreate(Activity.java:8000)
        at android.app.Activity.performCreate(Activity.java:7984)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
D/Capacitor: Registering plugin: WebView
D/Capacitor: Registering plugin: AdMob
D/Capacitor: Registering plugin: GoogleAuth
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.luyou.clauncher, PID: 11477
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.luyou.clauncher/com.luyou.clauncher.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference
        at com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth.load(GoogleAuth.java:47)
        at com.getcapacitor.PluginHandle.load(PluginHandle.java:95)
        at com.getcapacitor.PluginHandle.<init>(PluginHandle.java:59)
        at com.getcapacitor.Bridge.registerPlugin(Bridge.java:464)
        at com.getcapacitor.Bridge.registerAllPlugins(Bridge.java:419)
        at com.getcapacitor.Bridge.<init>(Bridge.java:164)
        at com.getcapacitor.Bridge$Builder.create(Bridge.java:1160)
        at com.getcapacitor.BridgeActivity.load(BridgeActivity.java:73)
        at com.getcapacitor.BridgeActivity.init(BridgeActivity.java:54)
        at com.getcapacitor.BridgeActivity.init(BridgeActivity.java:37)
        at com.luyou.clauncher.MainActivity.onCreate(MainActivity.java:19)
        at android.app.Activity.performCreate(Activity.java:8000)
        at android.app.Activity.performCreate(Activity.java:7984)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:223) 
        at android.app.ActivityThread.main(ActivityThread.java:7656) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
I/Process: Sending signal. PID: 11477 SIG: 9

capacitor.config.json已经在项目的根路径上,执行npx cap copynpx cap sync并不能解决这个问题,实际上是复制www文件。出于某种原因,电容器配置只是没有被复制。

jdg4fx2g

jdg4fx2g1#

看起来电容器alpha版本坏了,所以gonig回到电容器2. 4. 7修复了这个问题。capacitor.config.json加载正确,本机插件加载正常。

qlckcl4x

qlckcl4x2#

太棒了,谢谢@Adrian Legaspi。降级到电容器2.4.7为我解决了这个问题。
下面是我的package.json:

"dependencies": {
  ...
  "@capacitor/android": "^2.4.2",
  "@capacitor/core": "2.4.7",
  ..
},
"devDependencies": {
  ...
  "@capacitor/cli": "2.4.2",
  ...
}

相关问题