最近在 2018 年,谷歌宣布了 Android 中的新功能,称为动态功能模块
我从这个链接http://www.tellmehow.co/know-android-dynamic-delivery-module/#尝试了相同的功能
在我的项目中,我得到了模块应用程序,这是我的应用程序和动态模块作为 bigbazaar,
我正在使用以下方法在运行时下载动态方法。
private void downloadDynamicModule() {
try {
SplitInstallManager splitInstallManager =
SplitInstallManagerFactory.create(this);
SplitInstallRequest request =
SplitInstallRequest
.newBuilder()
.addModule("bigbazaar")
.build();
SplitInstallStateUpdatedListener listener = new SplitInstallStateUpdatedListener() {
@Override
public void onStateUpdate(SplitInstallSessionState splitInstallSessionState) {
if (splitInstallSessionState.sessionId() == mySessionId) {
switch (splitInstallSessionState.status()) {
case SplitInstallSessionStatus.INSTALLED:
Toast.makeText(MainActivity.this,
"Dynamic Module downloaded", Toast.LENGTH_SHORT).show();
cmdBigBazaar.setEnabled(true);
break;
}
}
}
};
splitInstallManager.registerListener(listener);
splitInstallManager.startInstall(request)
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
switch (((SplitInstallException) e).getErrorCode()) {
case SplitInstallErrorCode.MODULE_UNAVAILABLE:
Toast.makeText(MainActivity.this, "MODULE_UNAVAILABLE", Toast.LENGTH_SHORT).show();
}
}
})
.addOnSuccessListener(new OnSuccessListener<Integer>() {
@Override
public void onSuccess(Integer sessionId) {
mySessionId = sessionId;
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
从给定的链接和其他 bolgs 中,我发现我们可以通过 Google Play 商店测试此功能,最后使用名为“bundletool”的工具
我还按照示例链接中的建议更改了我的运行配置。
我还在动态功能模块的 AndroidManifest.xml 文件中定义了以下属性,
<dist:module
dist:onDemand="true"
dist:instant="false"
dist:title="@string/title_bigbazaar">
<dist:fusing dist:include="false" />
</dist:module>
错误日志,
06-05 10:43:55.452 17566-17566/com.dynamic I/PlayCore: UID: [11746] PID: [17566] SplitInstallListenerRegistry : registerListener
06-05 10:43:55.453 17566-17566/com.dynamic I/PlayCore: UID: [11746] PID: [17566] SplitInstallService : startInstall([dynamicmodule],[])
06-05 10:43:55.463 17566-18219/com.dynamic I/PlayCore: UID: [11746] PID: [17566] SplitInstallService : Initiate binding to the service.
06-05 10:43:55.504 17566-17566/com.dynamic I/PlayCore: UID: [11746] PID: [17566] SplitInstallService : ServiceConnectionImpl.onServiceConnected(ComponentInfo{com.android.vending/com.google.android.finsky.splitinstallservice.SplitInstallService})
06-05 10:43:55.505 17566-18219/com.dynamic I/PlayCore: UID: [11746] PID: [17566] SplitInstallService : linkToDeath
06-05 10:43:56.386 17566-17582/com.dynamic I/PlayCore: UID: [11746] PID: [17566] SplitInstallService : onError(-2)
06-05 10:43:56.387 17566-18219/com.dynamic I/PlayCore: UID: [11746] PID: [17566] SplitInstallService : Unbind from service.
06-05 10:43:56.387 17566-17566/com.dynamic D/MainActivity: Exception: com.google.android.play.core.splitinstall.SplitInstallException: Split Install Error: -2
06-05 10:43:56.387 17566-17566/com.dynamic W/System.err: com.google.android.play.core.splitinstall.SplitInstallException: Split Install Error: -2
06-05 10:43:56.387 17566-17566/com.dynamic W/System.err: at com.google.android.play.core.splitinstall.ag.e(Unknown Source)
06-05 10:43:56.387 17566-17566/com.dynamic W/System.err: at com.google.android.play.core.internal.bg.a(Unknown Source)
06-05 10:43:56.387 17566-17566/com.dynamic W/System.err: at com.google.android.play.core.internal.j.onTransact(Unknown Source)
06-05 10:43:56.387 17566-17566/com.dynamic W/System.err: at android.os.Binder.execTransact(Binder.java:453)
问题
我尝试了很多方法,但是每次单击下载按钮下载动态模块时,它都会给我错误代码-2,即“MUDULE_UNAVAILABLE”。
我该如何解决这个错误?