嗨,我正在研究动态功能模块。我有时将.aab文件上传到playstore中,但应用程序无法打开模块,引发了这样的错误。
this is the error getting in logcat
PID: 12715
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.testDynamic/com.testDynamic.zco.ZcoActivity}:
java.lang.ClassNotFoundException: Didn't find class
"com.testDynamic.zco.ZcoActivity"
on path: DexPathList[[zip file
"/data/app/com.testDynamic-1/base.apk",
这是我的代码。
这是我的主应用清单文件。
<?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.testDynamic">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<dist:module dist:instant="true" />
<application
android:name=".Application"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
这是我的模块清单
<?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.testDynamic.zco"
split="dynamiczco">
<dist:module
dist:onDemand="true"
dist:title="@string/title_test">
<dist:fusing dist:include="true" />
</dist:module>
<application>
<activity
android:name="com.testDynamic.module.ZcoActivity"
android:label="@string/title_activity_test"
android:theme="@style/AppTheme.NoActionBar">
</activity>
</application>
</manifest>
这是我的主要礼物
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.testDynamic"
minSdkVersion 23
targetSdkVersion 27
versionCode 33
versionName "3.1"
}
dynamicFeatures = [":dynamicmodule",":dynamic_feature2",":dynamiczco"]
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
}
dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
api 'com.android.support:appcompat-v7:27.1.1'
api 'com.android.support:recyclerview-v7:27.1.1'
api 'com.google.android.play:core:1.3.1'
api 'com.android.support.constraint:constraint-layout:1.1.2'
api 'com.squareup.retrofit2:retrofit:2.1.0'
api 'com.squareup.retrofit2:converter-gson:2.1.0'
api 'com.android.support:cardview-v7:27.1.1'
}
这是我的模块gradle
apply plugin: 'com.android.dynamic-feature'
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 20
targetSdkVersion 27
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':app')
// implementation 'com.google.android.material:material:27.0.+'
}
有人对此错误有想法,请帮助我解决
任何人都可以解决此问题。 预先感谢。
答案 0 :(得分:0)
您好,研究后我找到了解决方案。现在,该模块正在下载,没有任何崩溃。
我更改了模块清单
<dist:module
dist:onDemand="true"
dist:title="@string/title_test">
<dist:fusing dist:include="true" />
到
<dist:module
dist:instant="true"
dist:onDemand="false"
dist:title="@string/title_test">
<dist:fusing dist:include="true" />
</dist:module>
工作正常。 谢谢大家