classnotfoundException 获取如果我在成功下载后启动动态模块中的活动

imi*_*imi 2 java android android-app-bundle

通过内部测试,我可以下载动态功能模块。成功下载后,我正在使用包名称打开动态模块中的活动,但我遇到了类未找到异常。我检查了 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();
                }
            });
}
Run Code Online (Sandbox Code Playgroud)

小智 5

我遇到了同样的问题,我发现有时当您从 android studio 创建项目时,您的动态模块不会将其放入 apply plugin: 'kotlin-android'模块的build.gradle文件中。请验证它,如果不存在,请将其应用到模块 gradle 文件中。

如果您仍然无法找到错误,请检查以下链接:
1.如何创建动态模块?
2.如何下载动态模块?