stackover 上几乎所有可用的答案,我已经在过去 5-6 小时内尝试过,请不要标记重复 :)
我已经参考了Amazon Device Messaging 文档以集成到我的 android 项目中,一切都可以正常编译,但是当我运行这个项目时,它会崩溃并显示一条消息
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.MainActivity}: java.lang.RuntimeException:
Stub! You are bundling a stubbed jar in the apk! Please move it to the classpath instead.
我已经通过在 AndroidManifest.xml 中进行标记来使用“如果 ADM 不可用则优雅地降级”的方法,如下所示
<!-- You must explicitly enable ADM. You must also declare whether your application will run with or without ADM.
If you specify android:required="false", your app must degrade gracefully when ADM is unavailable. -->
<amazon:enable-feature android:name="com.amazon.device.messaging"
android:required="false" />
此外,在 MainActivity 文件中,我正在检查 ADM 的可用性,如下面的代码
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//some other codes here
boolean admAvailable = false;
try {
Class.forName( "com.amazon.device.messaging.ADM" );
admAvailable = true ;
}
catch (ClassNotFoundException e) {
// Handle the exception.
}
if(admAvailable) {
ADMManifest.checkManifestAuthoredProperly(getApplicationContext());
}
}