I'm new to Android Studio (SDK version 23), and trying to obtain ANDROID_ID by following the top answer in this post .
After importing the 'secure' class, when I try the suggested answer below, I get a "cannot resolve method getContext()" warning:
private String androidId = Secure.getString(getContext().getContentResolver(),Secure.ANDROID_ID);
I did a bit of digging around, and thought getApplicationContext() was worth a try:
private String androidId = Secure.getString(getApplicationContext().getContentResolver(),Secure.ANDROID_ID);
I don't get any warnings, and the app builds successfully. However if I try running it on a connected device, it crashes with the following error (summarized):
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
The app doesn't crash when I manually specify my androidId string:
private String androidId = "This works";
Any help would be greatly appreciated.
Problem solved thanks to this post .
In this case, it seemed the error was being caused by excessive dependencies (>65k) methods. It was corrected as follows:
Step 1
Modify gradle.build (app) to reference the MultiDexApplication class
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
...
multiDexEnabled true
}
...
dependencies {
...
compile 'com.android.support:multidex:1.0.0'
}
Step 2
Add the following attribute to the application tag in the manifest file:
<application
...
android:name="android.support.multidex.MultiDexApplication">
您可能在字符串名称中包含下划线,请在删除下划线后检查它....
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.