Monday, 15 February 2021

Android Dynamic Feature : Error -2 Module Unavailable

I have been debugging all day with no result, I've followed every documentation and google code labs and uploaded the bundle to internal testing and the error persists : Module Unavailable, below is my implementation:

Module AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest 
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:dist="http://schemas.android.com/apk/distribution"
 package="com.appshive.shop"
 >

<dist:module
    dist:instant="false"
    dist:title="@string/measure">
    <dist:delivery>
        <dist:on-demand />
    </dist:delivery>
    <dist:fusing dist:include="true" />
</dist:module>
</manifest>

Module build.gradle:

plugins {
id 'com.android.dynamic-feature'
id 'kotlin-android'
id 'kotlin-kapt'
id 'kotlin-android-extensions'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"

defaultConfig {
    minSdkVersion 22
    targetSdkVersion 30
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = '1.8'
}
}

and the module have fragments along with some dependencies for the them.

In the base app Android Manifest:

I've added this

dynamicFeatures = [':measure']
android:name=".core.ShopApplication"

and my application id in build.gradle is : com.appshive.ecommerce

my application class extends SplitCompatApplication

class ShopApplication: SplitCompatApplication(){

override fun onCreate() {
    super.onCreate()
    Timber.plant(DebugTree())
    SplitCompat.install(this)
    startKoin {
        androidContext(this@ShopApplication)
        modules(listOf(appModule, repoModule))
    }

}

I have only 1 activity in all the project: Main Activity and it contain

private lateinit var manager: SplitInstallManager

and in onCreate I initialised it : manager = SplitInstallManagerFactory.create(this)

and I'm checking if module is available I'm opening the fragment else:

val request = SplitInstallRequest.newBuilder()
    .addModule(name)
    .build()

manager.startInstall(request).addOnSuccessListener {
    makeToast("Successss")
}.addOnFailureListener { e->
    makeToast(e.message.toString()+" as")
}

and I am registering listener to the manager:

override fun onPause() {
    manager.unregisterListener(listener)
    super.onPause()
}
override fun onResume() {
    manager.registerListener(listener)
    super.onResume()
}

that's all and then I generate signed bundle using my key and upload it to internal test after that I install it on my phone and then an error occurs : Error -2 Module Unavailable

I have tried all the methods on the internet with no luck I don't know what I'm missing. is it because of bundle signing or because of packaging?

when I change the module to install time module it works like a charm.



from Android Dynamic Feature : Error -2 Module Unavailable

No comments:

Post a Comment