【问题标题】:Getting ANDROID_ID Failed resolution of ...R$string;获取 ANDROID_ID ...R$string 的解析失败;
【发布时间】:2016-03-06 08:43:54
【问题描述】:

我是 Android Studio(SDK 版本 23)的新手,并尝试按照 this post 中的最佳答案获取 ANDROID_ID。

导入“安全”类后,当我尝试以下建议的答案时,我收到“无法解析方法 getContext()”警告:

private String androidId = Secure.getString(getContext().getContentResolver(),Secure.ANDROID_ID);

我做了一些挖掘,认为 getApplicationContext() 值得一试:

private String androidId = Secure.getString(getApplicationContext().getContentResolver(),Secure.ANDROID_ID);

我没有收到任何警告,并且应用程序构建成功。但是,如果我尝试在连接的设备上运行它,它会崩溃并出现以下错误(总结):

java.lang.NoClassDefFoundError: 解析失败:Lcom/google/android/gms/R$string;

在 com.google.android.gms.measurement.zza.(未知来源)

...

原因:java.lang.ClassNotFoundException:在路径上找不到类“com.google.android.gms.R$string”:DexPathList[[zip 文件“/data/app/application.myproject/base. apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]

...

原因:java.lang.NoClassDefFoundError: Class not found using the boot class loader;没有可用的堆栈

当我手动指定我的 androidId 字符串时,应用程序不会崩溃:

private String androidId = "This works";

任何帮助将不胜感激。

【问题讨论】:

  • 我认为你的“com.google.android.gms”有问题;这是谷歌播放服务
  • 在 build.gradle (app) 中,我指定: compile 'com.google.android.gms:play-services:8.4.0'

标签: java android-studio


【解决方案1】:

感谢this post,问题解决了。

在这种情况下,错误似乎是由excessive dependencies (>65k) 方法引起的。已更正如下:

第 1 步

修改 gradle.build (app) 以引用 MultiDexApplication 类

android {
compileSdkVersion 23
buildToolsVersion "23.0.0"

defaultConfig {

    ...

    multiDexEnabled true
}

    ...

dependencies {
    ...

    compile 'com.android.support:multidex:1.0.0'
}

第 2 步

将以下属性添加到清单文件中的应用程序标记:

<application
    ...
    android:name="android.support.multidex.MultiDexApplication">

【讨论】:

    【解决方案2】:

    字符串名称中可能包含下划线,删除下划线后检查...

    【讨论】:

      猜你喜欢
      • 2018-10-26
      • 1970-01-01
      • 1970-01-01
      • 2021-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-11
      相关资源
      最近更新 更多