NoClassDefFoundError when trying to build google api client - android

today i added the google play services library to my project. I have followed the instructions which are given on http://developer.android.com/google/play-services/setup.html#ensure
Screenshot of my Settings: https://drive.google.com/file/d/0Bwe9sI6XZ6rcZGZzdmlaQjVheDA/edit?usp=sharing
The problem is when I try to execute the following code, a noclassdeffounderror exception raises.
public class MainActivity extends Activity {
private GoogleApiClient mGoogleClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
mGoogleClient = new GoogleApiClient.Builder(this)
.addApi(Games.API)
.addScope(Games.SCOPE_GAMES)
.setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL)
.build();
In the logcat the exception looks like
threadid=1: thread exiting with uncaught exception (group=0x40d02930)
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gms.common.api.GoogleApiClient$Builder
at com.gmail.mhofer4991.at.taptorotate.MainActivity.onCreate(MainActivity.java:104)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2147)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$600(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5074)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Force finishing activity com.example.taptorotate/com.gmail.mhofer4991.at.taptorotate.MainActivity
I also have cleaned and rebuilt the project.
It's driving me crazy that i cannot solve the problem. I know there are already other threads with the same topic and I also tried some solutions which were suggested there but none of them worked for me. Please help me out!

I also had same problem,
java.lang.NoClassDefFoundError:
com.google.android.gms.common.api.GoogleApiClient$Builder
I was using the below dependency on the application build.gradle file.
compile 'com.google.android.gms:play-services:7.8.0'
I changed it to
compile 'com.google.android.gms:play-services-plus:7.8.0'
I updated the Google Play Services (Rev 26) and Google Repository(Rev 20).
After that the exception doesn't occur.
Try to use individual APIs and corresponding build.gradle descriptions as mensioned in the following page,
https://developers.google.com/android/guides/setup#ensure

Try to add obfuscation rules for the Google API's if you have minifyEnabled or ProGuard set to true:
ProGuard Configuration

tryin to work with an implementation of Google Drive in Android i´ve found this error message pointing some classes like:
java.lang.ClassNotFoundException: com.google.android.gms.common.api.Scope
Caused by: java.lang.ClassNotFoundException: Didn't find class
I have found that the real problem is the limit of 64K references when we add dependencies related to GoogleApiClient, so adding multidex support solved my problem:
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
...
...
multiDexEnabled true
}
...
...

Related

Issue with Maps SDK for Android

I am fairly new to android app development. Today i tried to implement a map inn my app, and cannot make it work. I even tried to make a new app with the default map activity, which crashes instantly.
This is the error I am getting:
--------- beginning of crash
2018-12-25 23:03:24.440 8401-8428/? E/AndroidRuntime: FATAL EXCEPTION: Thread-5
Process: com.example.krist.maptest, PID: 8401
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;
at ez.b(:com.google.android.gms.dynamite_mapsdynamite#14799081#14.7.99 (100400-223214910):3)
at ey.a(:com.google.android.gms.dynamite_mapsdynamite#14799081#14.7.99 (100400-223214910):3)
at fa.a(:com.google.android.gms.dynamite_mapsdynamite#14799081#14.7.99 (100400-223214910):15)
at com.google.maps.api.android.lib6.drd.al.a(:com.google.android.gms.dynamite_mapsdynamite#14799081#14.7.99 (100400-223214910):6)
at ed.a(:com.google.android.gms.dynamite_mapsdynamite#14799081#14.7.99 (100400-223214910):21)
at ed.run(:com.google.android.gms.dynamite_mapsdynamite#14799081#14.7.99 (100400-223214910):8)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.ProtocolVersion" on path: DexPathList[[zip file "/data/user_de/0/com.google.android.gms/app_chimera/m/00000016/MapsDynamite.apk"],nativeLibraryDirectories=[/data/user_de/0/com.google.android.gms/app_chimera/m/00000016/MapsDynamite.apk!/lib/arm64-v8a, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at ad.loadClass(:com.google.android.gms.dynamite_dynamiteloader#14799081#14.7.99 (100400-223214910):4)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at ez.b(:com.google.android.gms.dynamite_mapsdynamite#14799081#14.7.99 (100400-223214910):3) 
at ey.a(:com.google.android.gms.dynamite_mapsdynamite#14799081#14.7.99 (100400-223214910):3) 
at fa.a(:com.google.android.gms.dynamite_mapsdynamite#14799081#14.7.99 (100400-223214910):15) 
at com.google.maps.api.android.lib6.drd.al.a(:com.google.android.gms.dynamite_mapsdynamite#14799081#14.7.99 (100400-223214910):6) 
at ed.a(:com.google.android.gms.dynamite_mapsdynamite#14799081#14.7.99 (100400-223214910):21) 
at ed.run(:com.google.android.gms.dynamite_mapsdynamite#14799081#14.7.99
(100400-223214910):8) 
I am running on a Pixel 3XL with the latest updates. Any ideas what the issue might be? Thanks.
I also had same issue, and it was solved pasting this line of code to 'application' element of AndroidManifest.xml.
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
Hope it helped you.
Check if dependencies are set up correctly. Play services and gmaps versions should not vary.
Enable multidexing in your build.
add this line in dependencies:
implementation 'com.android.support:multidex:1.0.3' and make these changes in defaultConfig:
android {
defaultConfig {
...
multiDexEnabled true
}
...
}
And sync project.

java.lang.NoClassDefFoundError: com.google.android.gms.R$string at com.google.android.gms.common.internal.zzam.<init>(Unknown Source)

I am building an Android App and everything works correctly for Android 5.+. However, for Android 4.x, I am getting the following error when I try to compile using Android Studio:
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gms.R$string
at com.google.android.gms.common.internal.zzam.<init>(Unknown Source)
at com.google.firebase.FirebaseOptions.fromResource(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1064)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:5181)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4733)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4666)
at android.app.ActivityThread.access$1300(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1439)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5455)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:966)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:733)
at dalvik.system.NativeStart.main(Native Method)
In my dependencies, I already tried both compile 'com.google.android.gms:play-services:+'
and also compile 'com.google.android.gms:play-services:9.8.0'.
I have been trying to find solutions online and people recommend to add Google Play Services dependencies, but I already did that. I had also tried compile 'com.android.support:multidex:1.0.0' but I do not think that would make any difference because in any case, I saw this message popping up in Android Studio:
"Instant Run does not support deploying build variants with multidex enabled, to a target with API level 20 or below.
To use Instant Run with a multidex enabled build variant, deploy to a target with API level 21 or higher."
Any hints? Thank you.
The solution was simply adding the following code in my class that extended Application:
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
The solution was at java.lang.NoClassDefFoundError: com.google.android.gms.internal.zzmp, so this question could be marked as duplicate.

Android Studio 2.3 not working with instant run: debug apk crash with ClassNotFoundException

After Android Studio 2.3 update (and gradle update) if I have instant run activated, and I install app from Android Studio through run or generate signed apk it works fine.
If I manually install the debug apk it immediately crashes on opening, with ClassNotFoundException.
Note: if I remove the reference to the file provider, the class not found becomes the main activity. This issue is with the debug apk that getting generated in Build-->Output-->apk folder. If you run app directly it always run fine.
Without instant run there is no crash. With previous versions of Android Studio there was not crash either.
java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.vfirst.ifbagro-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.vfirst.ifbagro-1, /vendor/lib, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:4993)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4596)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4536)
at android.app.ActivityThread.access$1300(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5214)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.vfirst.ifbagro-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.vfirst.ifbagro-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.ActivityThread.installProvider(ActivityThread.java:4978)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4596)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4536)
at android.app.ActivityThread.access$1300(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5214)
at java.lang.reflect.Method.invokeNative(Native Method)
I had the same error and I solved it with MultiDex
add build.gradle multiDexEnabled "true".
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 25
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
described on this link : https://developer.android.com/studio/build/multidex.html
Try this :
android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 25
multiDexEnabled true
}
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
this code into your manifest :
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
If you use custom application class, use this code :
public class YouApplication extends Application {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
and then for manifest :
<application
...
android:name="YOUR_PACKAGE.YouApplication">
...
</application>
I hope help you my friend
As for me I tried the following : Try to check if your phone's Auto-start Manager allows your app to auto-start. By allowing your app to auto-start I think will help in fixing the Instant-run Problem. Hope's this helps.

Android NoClassDefFoundError crash after new couchbase Lite Jars added

The the same crash happened after I imported Couchbase Lite Android using either Gradle or jars.
Couldn't really figure out what's going on here as I didn't touch the code and only dropped the jars into the "libs" folder.
// inside Custom Application class
#Override
public void onCreate() {
super.onCreate();
Fabric.with(this, new Crashlytics()); // <===== Crash here!
}
Trace:
07-07 19:37:43.785 15247-15247/? E/AndroidRuntime﹕
FATAL EXCEPTION: main
Process: sg.com.bigspoon.www, PID: 15247
java.lang.NoClassDefFoundError: io.fabric.sdk.android.services.common.ExecutorUtils
at com.crashlytics.android.Crashlytics.<init>(Crashlytics.java:202)
at com.crashlytics.android.Crashlytics.<init>(Crashlytics.java:197)
at sg.com.bigspoon.www.data.BigSpoon.onCreate(BigSpoon.java:121)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4541)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1381)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
at dalvik.system.NativeStart.main(Native Method)
EDIT:
Although this is "fixed". But it is still very bizarre why this is happening. I would enlighten me and I would mark it as correct answer instead.
This is solved by enabling multiDex in build.gradle
android {
defaultConfig {
// Lower than 14 doesn't support multidex
minSdkVersion 14
// Enabling multidex support.
multiDexEnabled true
}
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
SOURCE and more details -->
https://github.com/chrisjenx/Calligraphy/issues/136
https://developer.android.com/tools/building/multidex.html

Rare Android Unable to Instantiate Application Exception

I'm seeing the following exception under Crashes in the dev console from time to time.
Whats puzzling about it is that google maps shows up in the call stack as if its calling or creating my app class - very confusing. Whats further weird is the "MyApp-2.apk" in the call stack - where it appends the "-2".
I do include the android.maps.jar file in the libs.
I would like to know how to recreate this if possible and how to prevent this from happening?
java.lang.RuntimeException: Unable to instantiate application com.MyApp.MyCustomApp:
java.lang.ClassNotFoundException: Didn't find class "com.MyApp.MyCustomApp"
on path: /system/framework/com.google.android.maps.jar:/data/app/com.MyApp-2.apk
at android.app.LoadedApk.makeApplication(LoadedApk.java:503)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4405)
at android.app.ActivityThread.access$1400(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1327)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5059)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.MyApp.MyCustomApp" on path: /system/framework/com.google.android.maps.jar:/data/app/com.MyApp-2.apk
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newApplication(Instrumentation.java:967)
at android.app.LoadedApk.makeApplication(LoadedApk.java:498)
... 11 more
Manifest Application Tag:
<application
android:name=".MyApp"
android:hardwareAccelerated="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:theme="#style/AppBaseTheme" >
I'm using these JARS: android-support-v4-r2-googlemaps.jar + android-support-v4.jar
The prime reason why a Class within your application would be present on your test devices but missing at runtime on some others would be if your class has a dependency on some external feature which is missing on those devices. For example, if you used some Google API which is not part of AOSP and so missing on a plain AOSP build, or a vendor build which does not license these, then your class will be pruned at install time as its dependencies cannot be resolved.
A common reason for your app finding its way into such circumstances might be someone running an inconsistently assembled "custom ROM" on their device.

Categories

Resources