Search code examples
androidangularionic-frameworkconfigcapacitor

Capacitor: Unable to load capacitor.config.json


Creating an Ionic 5 app with Capacitor, I'm running into this problem where it seems that capacitor.config.json is not being loaded.

This problem came after I've installed @codetrix-studio/capacitor-google-auth, before the project was running on android fine.

{
  "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
    }
  }
}

On the android studio the build goes okay but when you try to open the app, it does crash with the following:

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 is already on the root path of the project and doing npx cap copy or npx cap sync doesn't solve this problem, but actually is copying the www files. For some reason, the capacitor config simply is just not being copied.


Solution

  • Seems like Capacitor alpha versions are broken, so gonig back to Capacitor 2.4.7 fixes the problem. The capacitor.config.json is loading correctly and the native plugins are loading fine.