oortCloud
oortCloud

Reputation: 496

Getting ANDROID_ID Failed resolution of ...R$string;

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.

Upvotes: 1

Views: 4884

Answers (2)

Sheriff
Sheriff

Reputation: 868

You might contain underscore in name of string, check it after removing underscore....

Upvotes: 0

oortCloud
oortCloud

Reputation: 496

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">

Upvotes: 2

Related Questions