我是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);
我沒有得到任何警告,和應用程序成功生成。
private String androidId = "This works";
任何:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/R$string;
at com.google.android.gms.measurement.zza.(Unknown Source)
...
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.R$string" on path: DexPathList[[zip file "/data/app/application.myproject/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
...
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
當我手動指定我androidId字符串中的應用程序不會崩潰:但是,如果我嘗試連接的設備上運行,它與下面的錯誤(總結)崩潰幫助將不勝感激。
我認爲你對「com.google.android.gms」有問題;這是谷歌播放服務 –
在build.gradle(應用程序),我已經指定:compile'com.google.android.gms:play-services:8.4.0' – oortCloud