2016-03-06 42 views
1

我是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字符串中的應用程序不會崩潰:但是,如果我嘗試連接的設備上運行,它與下面的錯誤(總結)崩潰幫助將不勝感激。

+0

我認爲你對「com.google.android.gms」有問題;這是谷歌播放服務 –

+0

在build.gradle(應用程序),我已經指定:compile'c​​om.google.android.gms:play-services:8.4.0' – oortCloud

回答

1

由於this post已解決問題。

在這種情況下,似乎錯誤是由excessive dependencies(> 65k)方法引起的。

步驟1

修改gradle.build(應用程序),以引用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"> 
相關問題