首页 > 解决方案 > CodenameOne - 使用 android.buildToolsVersion=27 构建时,Android 应用程序无法启动

问题描述

我正在使用 gcm,但由于此错误,应用程序无法启动:

AndroidRuntime: java.lang.IllegalAccessError: Method 'void android.support.v4.content.ContextCompat.()' is inaccessible to class 'com.google.android.gms.iid.zzd' (declaration of 'com.google.android .gms.iid.zzd' 出现在 /data/app/net.segoia.opengroups.mobile-1/base.apk:classes2.dex 中)

这是由这一行引起的:

InstanceID instanceID = InstanceID.getInstance(this);

问题是在为 api 级别 27 构建时,对 android v4 的支持被放弃了。

标签: androidgoogle-cloud-messagingcodenameone

解决方案


解决问题的方法是添加这两个构建提示:

android.supportV4=true
android.supportv4Dep=compile 'com.android.support:support-v4:23.+'

这需要一段时间才能弄清楚,特别是因为 android.supportV4Dep 甚至没有文档记录,单独的 android.supportV4 是不够的。我从另一个 stackoverflow 对另一个问题的回答中了解了 android.supportV4Dep,所以我想我会在这里记录一下。


推荐阅读