timbru31 / cordova-plugin-lottie-splashscreen

🐣 🎬 📱 Apache Cordova plugin to show Lottie animations as the splash screen with Airbnb's Lottie wrapper
https://www.npmjs.com/package/cordova-plugin-lottie-splashscreen
MIT License
132 stars 54 forks source link

Android build crashes on startup #144

Closed egonzalez-T closed 4 years ago

egonzalez-T commented 4 years ago

Bug report

What steps will reproduce the problem?

Install the plugin and try to run it on android device

Expected output

What do you see instead?

App crashes

Log file of the issue/error

01-03 11:34:36.548 17915 17915 W System.err: java.lang.ClassNotFoundException: de.dustplanet.cordova.lottie.LottieSplashScreen
01-03 11:34:36.548 17915 17915 W System.err:    at java.lang.Class.classForName(Native Method)
01-03 11:34:36.548 17915 17915 W System.err:    at java.lang.Class.forName(Class.java:400)
01-03 11:34:36.548 17915 17915 W System.err:    at java.lang.Class.forName(Class.java:326)
01-03 11:34:36.548 17915 17915 W System.err:    at org.apache.cordova.PluginManager.instantiatePlugin(PluginManager.java:489)
01-03 11:34:36.548 17915 17915 W System.err:    at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:169)
01-03 11:34:36.548 17915 17915 W System.err:    at org.apache.cordova.PluginManager.startupPlugins(PluginManager.java:97)
01-03 11:34:36.548 17915 17915 W System.err:    at org.apache.cordova.PluginManager.init(PluginManager.java:86)
01-03 11:34:36.548 17915 17915 W System.err:    at org.apache.cordova.CordovaWebViewImpl.init(CordovaWebViewImpl.java:117)
01-03 11:34:36.548 17915 17915 W System.err:    at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:149)
01-03 11:34:36.548 17915 17915 W System.err:    at org.apache.cordova.CordovaActivity.loadUrl(CordovaActivity.java:224)
01-03 11:34:36.548 17915 17915 W System.err:    at com.tranzport.sit.MainActivity.onCreate(MainActivity.java:39)
01-03 11:34:36.548 17915 17915 W System.err:    at android.app.Activity.performCreate(Activity.java:6915)
01-03 11:34:36.548 17915 17915 W System.err:    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
01-03 11:34:36.549 17915 17915 W System.err:    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746)
01-03 11:34:36.549 17915 17915 W System.err:    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864)
01-03 11:34:36.549 17915 17915 W System.err:    at android.app.ActivityThread.-wrap12(ActivityThread.java)
01-03 11:34:36.549 17915 17915 W System.err:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567)
01-03 11:34:36.549 17915 17915 W System.err:    at android.os.Handler.dispatchMessage(Handler.java:105)
01-03 11:34:36.549 17915 17915 W System.err:    at android.os.Looper.loop(Looper.java:156)
01-03 11:34:36.549 17915 17915 W System.err:    at android.app.ActivityThread.main(ActivityThread.java:6517)
01-03 11:34:36.549 17915 17915 W System.err:    at java.lang.reflect.Method.invoke(Native Method)
01-03 11:34:36.549 17915 17915 W System.err:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
01-03 11:34:36.549 17915 17915 W System.err:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
01-03 11:34:36.549 17915 17915 W System.err: Caused by: java.lang.ClassNotFoundException: Didn't find class "de.dustplanet.cordova.lottie.LottieSplashScreen" on path: DexPathList[[zip file "/data/app/com.tranzport.sit-1/base.apk"],nativeLibraryDirectories=[/data/app/com.tranzport.sit-1/lib/arm64, /data/app/com.tranzport.sit-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64, /system/vendor/lib64, /product/lib64]]
01-03 11:34:36.549 17915 17915 W System.err:    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
01-03 11:34:36.549 17915 17915 W System.err:    at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
01-03 11:34:36.549 17915 17915 W System.err:    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
01-03 11:34:36.549 17915 17915 W System.err:    ... 23 more
01-03 11:34:36.549 17915 17915 I System.out: Error adding plugin de.dustplanet.cordova.lottie.LottieSplashScreen.
01-03 11:34:36.552 17915 17915 E AndroidRuntime: FATAL EXCEPTION: main
01-03 11:34:36.552 17915 17915 E AndroidRuntime: Process: com.tranzport.sit, PID: 17915
01-03 11:34:36.552 17915 17915 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tranzport.sit/com.tranzport.sit.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CordovaPlugin.privateInitialize(java.lang.String, org.apache.cordova.CordovaInterface, org.apache.cordova.CordovaWebView, org.apache.cordova.CordovaPreferences)' on a null object reference

Version information

Ionic:

   Ionic CLI                     : 5.4.4 
   Ionic Framework               : @ionic/angular 4.7.0
   @angular-devkit/build-angular : 0.801.1
   @angular-devkit/schematics    : 8.1.1
   @angular/cli                  : 8.1.1
   @ionic/angular-toolkit        : 2.0.0

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : android 8.1.0, browser 5.0.4, ios 5.1.1
   Cordova Plugins   : cordova-plugin-ionic-webview 2.5.3, (and 28 other plugins)

Utility:

   cordova-res : 0.8.1
   native-run  : 0.2.9 (update available: 0.3.0)

System:

   Android SDK Tools : 26.1.1
   ios-deploy        : 1.9.4
   ios-sim           : 6.1.3
   NodeJS            : v10.16.0 (/usr/local/bin/node)
   npm               : 6.11.3
   OS                : macOS Mojave
   Xcode             : Xcode 11.2 Build version 11B52

Please provide any additional information below.

Plugin preferences:

   <preference name="LottieAnimationLocation" value="www/assets/splash.json" />
    <preference name="LottieWidth" value="350" />
    <preference name="LottieHeight" value="350" />
    <preference name="LottieHideTimeout" value="5" />
    <preference name="LottieAutoHideSplashScreen" value="false" />
    <preference name="SwiftVersion" value="4.2" />

Checklist

timbru31 commented 4 years ago

Can you please provide some more information in regards to your build pipeline? How did you add the Android platform and the plugin? Are you using Ionic, Ionic AppFlow, Fastlane or something similar?

egonzalez-T commented 4 years ago

I am using Ionic. I add the plugin using ionic cordova plugin add cordova-plugin-lottie-splashscreen. Plugin version is 0.7.1 and the android prerequisites are installed

"cordova-plugin-androidx": "^1.0.2",
"cordova-plugin-androidx-adapter": "^1.0.2"
castelar007 commented 4 years ago

after ionic cordova build android try run: node plugins/cordova-plugin-lottie-splashscreen/hooks/android/copy_build_extras.js

timbru31 commented 4 years ago

That’s my idea what could be missing, too. I still have to debug, if ionic does omit the necessary hooks.

Besides that, I’m adding some more testing to the project (something like #129 but with ionic instead)

egonzalez-T commented 4 years ago

@castelar007 @timbru31 I got the same result after installing the plugin clean and then running node plugins/cordova-plugin-lottie-splashscreen/hooks/android/copy_build_extras.js

timbru31 commented 4 years ago

Could you possibly create a debug project which shows the issue and either push it as a git repo or provide the project as a zip file?

egonzalez-T commented 4 years ago

Ok so I think I have more clarification on the issue. I tried to create new repo and couldn't reproduce the problem. I started installing my plugins one by one thinking that it was a conflict with one of the other plugins. The problem ends up being the build-extras.gradle with contents

android {
    defaultConfig {
        multiDexEnabled true
    }
}

dependencies {
    compile 'com.android.support:multidex:1.0.1'
}

With this file copied into app/build-extras.gradle I encounter the issue with lottie. Any advice?

timbru31 commented 4 years ago

What’s the plugin name that installs these dependencies? I’ll take a look at this combo of plugins then 👍

egonzalez-T commented 4 years ago

ionic-conference-app 2.zip Here is the zip file of the test repo with the lottie plugin installed.

Screen Shot 2020-01-10 at 3 14 43 PM

Note the app crashes when the build-extras.gradle is included through <resource-file src="build-extras.gradle" target="app/build-extras.gradle" />

The only thing the build.gradle-extras file is doing is enabling multidex

egonzalez-T commented 4 years ago

Thanks for the help!

timbru31 commented 4 years ago

Alright, so the problem is caused because you specify the build-extras.gradle as a resource file. The lottie-plugin needs to enable Kotlin support in this file, too. However, during a Cordova build the file is replaced by yours, because you specify it as a resource file which the build process replaces.

Could you instead try to use, e.g., this plugin over manually enabling the multidex support via a resource-file? https://github.com/phonegap/phonegap-plugin-multidex In my test with your debug app, it worked.

egonzalez-T commented 4 years ago

That worked. Thanks for the help!

timbru31 commented 4 years ago

Glad that solved the issue!

mruta2020 commented 4 years ago

@timbru31 Hi, I keep getting this error on the following environment instead:

cordova 10.0.0
cordova-android: 9.0.0
cordova-plugin-lottie-splashscreen: 0.9.1

I also tried installing plugin-enable-multidex, but nothing.

timbru31 commented 4 years ago

First of all, read the FAQ.md (https://github.com/timbru31/cordova-plugin-lottie-splashscreen/blob/master/FAQ.md#failure-build-failed-with-an-exception) especially the last two entries. If you can't solve it, please open a new issue and follow the issue template, thanks!