【发布时间】:2019-05-24 12:58:31
【问题描述】:
通过内部测试,我可以下载动态功能模块。成功下载后,我正在使用包名称打开动态模块中的活动,但我发现类未找到异常。我检查了 APK 大小,但大小没有增加。下面是我的代码。请帮忙
下面是我下载模块的代码。我从 Playstore 中提供的内部测试中使用。
public void loadFeatureTwo() {
// Builds a request to install the feature1 module
SplitInstallRequest request =
SplitInstallRequest
.newBuilder()
// You can download multiple on demand modules per
// request by invoking the following method for each
// module you want to install.
.addModule("feature2")
.build();
// Begin the installation of the feature1 module and handle success/failure
splitInstallManager
.startInstall(request)
.addOnSuccessListener(new OnSuccessListener<Integer>() {
@Override
public void onSuccess(Integer integer) {
// Module download successful
/* Intent intent = new Intent().setClassName(getPackageName(), "com.bapspatil.feature2.FeatureTwoActivity");
startActivity(intent);*/
Toast.makeText(getApplicationContext(), "successfully download feature2: ", Toast.LENGTH_LONG).show();
try {
Intent myIntent = new Intent(MainActivity.this, Class.forName("com.bapspatil.feature2.FeatureTwoActivity"));
startActivity(myIntent);
} catch (Exception e) {
e.printStackTrace();
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
// Module download failed; handle the error here
Toast.makeText(getApplicationContext(), "Couldn't download feature: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
【问题讨论】:
-
您是否与 SplitCompat 集成? developer.android.com/guide/app-bundle/…
-
@Pierre 非常感谢。我没有放那个。
-
@Pierre 我仍然收到此异常 java.lang.ClassNotFoundException:在路径上找不到类“com.bapspatil.feature2.FeatureTwoActivity”:DexPathList [[zip 文件“/data/app/ com.imimobile.androidappbundledemo-xo4sNaGIZ60bGZFxT5o_GQ==/base.apk”,压缩文件“/data/app/com.imimobile.androidappbundledemo-xo4sNaGIZ60bGZFxT5o_GQ==/split_config.en.apk”,压缩文件“/data/app/com. imimobile.androidappbundledemo-xo4sNaGIZ60bGZFxT5o_GQ==/split_config.xxhdpi.apk"],nativeLibraryDirectories=[/data/app/com.imimobile.androidappbundledemo-xo4sNaGIZ60bGZFxT5o_GQ==/lib/x86, /system/lib]]
-
@Pierre 我在应用模块清单 android:name="com.google.android.play.core.splitcompat.SplitCompatApplication" 中添加了这一行
标签: java android android-app-bundle