Giter Site home page Giter Site logo

googlesamples / android-dynamic-code-loading Goto Github PK

View Code? Open in Web Editor NEW
423.0 423.0 65.0 148 KB

Android dynamic code loading sample for Dynamic Feature Modules.

Home Page: https://medium.com/androiddevelopers/patterns-for-accessing-code-from-dynamic-feature-modules-7e5dca6f9123

License: Other

Kotlin 100.00%

android-dynamic-code-loading's Issues

App is crashed when it is built with serviceLoaderDebug

Summary

This app is crashed with the following stacktrace:

2019-05-12 00:14:54.688 19151-19151/com.google.android.samples.dynamiccodeloading E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.google.android.samples.dynamiccodeloading, PID: 19151
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.samples.dynamiccodeloading/com.google.android.samples.dynamiccodeloading.MainActivity}: java.util.NoSuchElementException
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.util.NoSuchElementException
        at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:366)
        at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:416)
        at java.util.ServiceLoader$1.next(ServiceLoader.java:494)
        at com.google.android.samples.dynamiccodeloading.MainViewModel.initializeStorageFeature(MainViewModel.kt:67)
        at com.google.android.samples.dynamiccodeloading.AbstractMainViewModel.loadCounter(AbstractMainViewModel.kt:81)
        at com.google.android.samples.dynamiccodeloading.MainActivity.onCreate(MainActivity.kt:65)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6669) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 

The crashed app is built with the buildType of serviceLoaderDebug.
The crash seems to be fixed by modifying app/src/serviceLoader/java/com/google/android/samples/dynamiccodeloading/MainViewModel.kt to pass a classloader to ServiceLoader.load() like

        val serviceLoader = ServiceLoader.load(
            StorageFeature.Provider::class.java, StorageFeature.Provider::class.java.classLoader
        )

Bebez

gradlew reflectDebug or ./gradlew serviceLoaderDebug or ./gradlew daggerDebug

The release variant not work

I just follow this post on medium and make some feature with same structure.
on debug variant everything is fine, but on release variant and upload it to playstore didn't work as expected.

I use latest dagger version : 2.42

I guess this line return null instance :

val provider = Class.forName(PROVIDER_CLASS).kotlin.objectInstance as StorageFeature.Provider

I have asked on SO and not have answer yet. Thanks in advance.

getting the crash when open the module

Hi ,
I am getting the crash while opening the module from the app. I was uploaded the .aab file into play store. I run the app downloaded from the play store. some times the module was opening after uninstall and reinstall the app then the module get crash some times.

PLease help me to resolve this issue. I struck over this.

I got this crash report in the logcat.

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.testDynamic, PID: 5047
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.testDynamic/com.testDynamic.module.NumberFacts}: java.lang.ClassNotFoundException: Didn't find class "com.testDynamic.module.NumberFacts" on path: DexPathList[[zip file "/data/app/com.testDynamic-1/base.apk", zip file "/data/app/com.testDynamic-1/split_config.en.apk", zip file "/data/app/com.testDynamic-1/split_config.xxhdpi.apk"],nativeLibraryDirectories=[/data/app/com.testDynamic-1/lib/arm64, /system/lib64, /vendor/lib64]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2626)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2785)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1532)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6342)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.testDynamic.module.NumberFacts" on path: DexPathList[[zip file "/data/app/com.testDynamic-1/base.apk", zip file "/data/app/com.testDynamic-1/split_config.en.apk", zip file "/data/app/com.testDynamic-1/split_config.xxhdpi.apk"],nativeLibraryDirectories=[/data/app/com.testDynamic-1/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2616)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2785)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1532)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6342)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.testDynamic-1/split_config.en.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:373)
at dalvik.system.DexFile.(DexFile.java:113)
at dalvik.system.DexFile.(DexFile.java:78)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:359)
at dalvik.system.DexPathList.makeElements(DexPathList.java:323)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:263)
at dalvik.system.DexPathList.(DexPathList.java:126)
at dalvik.system.BaseDexClassLoader.(BaseDexClassLoader.java:48)
at dalvik.system.PathClassLoader.(PathClassLoader.java:64)
at com.android.internal.os.PathClassLoaderFactory.createClassLoader(PathClassLoaderFactory.java:43)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:58)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:522)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:555)
at android.app.ActivityThread.getTopLevelResources(ActivityThread.java:1925)
at android.app.LoadedApk.getResources(LoadedApk.java:768)
at android.app.ContextImpl.(ContextImpl.java:2078)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2023)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5393)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1602)
... 6 more
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.testDynamic-1/split_config.xxhdpi.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:373)
at dalvik.system.DexFile.(DexFile.java:113)
at dalvik.system.DexFile.(DexFile.java:78)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:359)
at dalvik.system.DexPathList.makeElements(DexPathList.java:323)
2019-06-13 12:24:23.493 5047-5047/? E/AndroidRuntime: at dalvik.system.DexPathList.makeDexElements(DexPathList.java:263)
at dalvik.system.DexPathList.(DexPathList.java:126)
at dalvik.system.BaseDexClassLoader.(BaseDexClassLoader.java:48)
at dalvik.system.PathClassLoader.(PathClassLoader.java:64)
at com.android.internal.os.PathClassLoaderFactory.createClassLoader(PathClassLoaderFactory.java:43)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:58)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:522)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:555)
at android.app.ActivityThread.getTopLevelResources(ActivityThread.java:1925)
at android.app.LoadedApk.getResources(LoadedApk.java:768)
at android.app.ContextImpl.(ContextImpl.java:2078)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2023)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5393)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1602)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.