3

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.

Badran
  • 515
  • 1
  • 7
  • 21

1 Answers1

0

When I was working on this feature, I was testing with Playstore's Internal Test feature only.

Later on I came to know that there is another way to do it locally using a tool named Bundle Tool.

You can download it from given link. After downloading Bundle Tool file, you need to generate apk using it.

bundletool build-apks 
--bundle=app/build/outputs/bundle/debug/bundle.aab
--output=my_app.apks

Ref : Android App Bundle

PS. when I was doing this feature in my application, I was develop it using Java code, But I am 100% sure it will work with kotlin code as well.

Lucifer
  • 29,392
  • 25
  • 90
  • 143
  • Do you think that it could be the application id? my base app application id is : com.appshive.shop and my module is com.appshive.measure – Badran Feb 19 '21 at 18:00
  • @Badran, please check this link https://betterprogramming.pub/a-practical-guide-to-android-app-bundle-for-beginners-7e8d93831828 – Lucifer Feb 25 '21 at 15:39