Android studio and NoClassDefFoundError - android

I've been given a project that was already in development to continue. After importing it to Android Studio and doing all the configurations with libs and projects I compile it and run it on a device but i get all the time NoClassDefFoundError over and over.
I've been for the last two days doing fixes found on the web and paying close attention to the libs.
I currently have this:
this is the main android project:
this is one of the lib projects (zxing-android-minimal):
As soon as I build and deploy it to the device i get this fantastic erro:
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.zxing.client.android.camera.CameraConfigurationManager
at pt.novabase.ocr.poc.camera.PhotoModule.onResumeAfterSuper(PhotoModule.java:152)
at pt.novabase.ocr.poc.CameraActivity.onResume(CameraActivity.java:109)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
at android.app.Activity.performResume(Activity.java:3832)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2231)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2256)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1789)
at android.app.ActivityThread.access$1500(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
at dalvik.system.NativeStart.main(Native Method)
The com.google.zxing.client.android.camera.CameraConfigurationManager class is in the zxing project. This project is only included in the main project.
As I mentioned in at the start i've tried different configuration with the lib imports suggested on other question of this nature but none worked. So out of despair of losing another day's work on this I've posted this question.
Thanks for any help on this nightmare.

I've found what was happening.
the problem was that when i imported the project every project was noted as a library except for the for the zxing project. When deploying it created applications with those project and my main app didn't have access to it.
I had to go to the facets and check the is library module for the xzing project (for some reasion the android studio didn't recognize it as a lib on import like the rest of the projects.

Related

NoClassDefFoundError for GooglePlayServicesUtil on android

I want to use google cloud messeging in my android app. It worked for me however after organizing my classes in packages and cleaning my project it stopped working, I get following error : http://pastebin.com/uWgYW9fn
FATAL EXCEPTION: main 11-18 20:57:44.649: E/AndroidRuntime(15967):
java.lang.NoClassDefFoundError:
com.google.android.gms.common.GooglePlayServicesUtil 11-18
20:57:44.649: E/AndroidRuntime(15967):
activity.MainActivity.checkPlayServices(MainActivity.java:491) 11-18
20:57:44.649: E/AndroidRuntime(15967):
activity.MainActivity.onCreate(MainActivity.java:72) 11-18
20:57:44.649: E/AndroidRuntime(15967): at
android.app.Activity.performCreate(Activity.java:5133)
Basically I moved my activity from
myproject.android
to
myproject.android.activity
and it stopped working with the above error. For gcm setup I did the following:
1. Install Google Play services with SDK manager.
2. Import relevant classes into my activity
3. Added the google-play-services_lib.jar to build path
4. added it as library project
My project is a maven project, however there is no maven repo for the cloud messaging service. Any ideas whats wrong?
GooglePlayServices should be added as a library project (see Android menu), not as a JAR in the build path.
See more details here.

Android Studio/Gradle build can't find custom Application class

I'm using the new Android Studio and Gradle to build a test project. I set it up in the default way (new project wizard). Everything seems to work OK, except that I specify a custom Application instance in the manifest file. The app builds OK, but then crashes when run on the device with:
Caused by: java.lang.ClassNotFoundException: Didn't find class "co.touchlab.android.testapp.MyApplication" on path: /data/app/co.touchlab.android.testapp-1.apk
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newApplication(Instrumentation.java:968)
at android.app.LoadedApk.makeApplication(LoadedApk.java:499)
Intellij seems to think everything is OK, and if I take out the custom app it works (until I hit a screen that tries to use it, of course).
I'm probably going to copy this over into my normal build dir and give it a whirl on idea 12 till this is sorted, but its obviously something to figure out. Will try a totally stock app with a custom Application class and see if that has trouble as well.
Open your build.gradle file for your app and add this:
dependencies {
compile 'PATH_OF_MISSING_CLASS_HERE'
}

Google Play, Drive API sample code in IntelliJ

I'm following the Google Drive Quickstart on Android instructions and have it working in Eclipse/Kepler. (Juno is just plain dodgy.) However, I'm much more familiar with IntelliJ, so I'm trying to figure out how to install these APIs there in a corresponding manner.
I think I'm getting tripped up on the Drive API part. The Eclipse plugin installs Drive in some special way or place. I added Google-api-services-drive-v2-rev63-1.14.1-beta.jar as a library, same as the others (Google-play-services and the api_java_client). But when I run the application it comes back with
java.lang.NoClassDefFoundError: com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential
And I've also gotten a NoClassDefFoundError having to do with Drive$Builder.
In IntelliJ the .jar scopes are set to "Compile" except for the api_java_client libraries which are set to "Provided." None of them have "Export" checked.
Edit: added the module & dependency. I now have a different error:
04-07 00:39:59.766: ERROR/AndroidRuntime(10697): FATAL EXCEPTION: main
java.lang.NoClassDefFoundError:
com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential
at com.fallinghawks.weight4.App.onCreate(App.java:15)
App.java:15 is
credential = GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE);
I can find the class it's asking for....
Edit 2, after adding libraries per CrazyCoder's instructions:
It compiles, it runs, but I get the following error. I am sure I missed doing something exactly right, I'll try it again in a minute but in the meantime the error is:
04-10 18:02:35.120: ERROR/AndroidRuntime(740): FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at com.google.api.services.drive.Drive$Builder.build(Drive.java:7301)
at com.example.DriveQuickstart.MyActivity.getDriveService(MyActivity.java:110)
at com.example.DriveQuickstart.MyActivity.onActivityResult(MyActivity.java:49)
at android.app.Activity.dispatchActivityResult(Activity.java:5293)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3315)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3362)
at android.app.ActivityThread.access$1100(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1282)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
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)
Caused by: java.lang.NoClassDefFoundError: com.google.common.base.Preconditions
at com.google.api.services.drive.Drive.<clinit>(Drive.java:63)
(Hopefully final edit): Yes, I missed something and the beast is working! Thank you so much!!
Now I can use IntelliJ again to work on my "real" project... sooooo much better :)
I went ahead and created IntelliJ IDEA project from scratch, spent about 15 minutes, works just fine.
Download Drive API v2 library and dependencies.
Unpack it somewhere, open readme.html, spend a couple of minutes reading it to understand what jars are needed.
Create a new Android application project in IDEA using a wizard with com.example.drivequickstart package and MainActivity. Use Android 4.2.2 Google APIs as the Platform.
Copy the following jars from the downloaded Drive API library into the project libs folder (you should have learned which jars to use from the step 2):
google-api-client-1.14.1-beta.jar
google-api-client-android-1.14.1-beta.jar
google-http-client-1.14.1-beta.jar
google-http-client-android-1.14.1-beta.jar
google-http-client-gson-1.14.1-beta.jar
google-oauth-client-1.14.1-beta.jar
gson-2.1.jar
jsr305-1.3.9.jar
google-api-services-drive-v2-rev65-1.14.1-beta.jar
Configure a project library from these jars. It can be done by selecting the jars in the Project View, right click, Add as Library..., add this library to the dependencies of your main module.
File | Import Module, browse to ANDROID_SDK\extras\google\google_play_services\libproject\google-play-services_‌​lib, from the existing sources.
Add google-play-services.jar to the dependencies of the imported module, enable the Export checkbox, it should look like this.
Add the module created in step 6 to the dependencies of your main application module.
Copy MainActivity sample code from the Quick Start, step 4 into the MainActivity.java file replacing the old code, edit AndroidManifest.xml as well per the guide.
Build, run in the emulator or on the device to test (don't forget steps 1-2 from the Quick Start).
Or you can just download and use the completely isolated sample that I've created following the above steps (module from the step 6 is included in the project).
It failed for me in the emulator because of some Camera app error (the sample uses Camera and my emulator didn't have it configured), but worked on the Galaxy Nexus device. The sample takes a picture using the device camera and uploads it to your Google Drive.

How to load native library to android library project

First, my project structure is like this:
Android project A --> Android Library project B(contains some native so library) --> Java library C.
how the project A reference the android library project B:
The native library in the android library project B.
how the Android Library project B is library:
The load library code (in the android library project B) :
System.loadLibrary("G72x");
System.loadLibrary("H264Android");
The crash log :
12-27 20:32:51.698: E/AndroidRuntime(11589): FATAL EXCEPTION: Thread-1694
12-27 20:32:51.698: E/AndroidRuntime(11589): java.lang.UnsatisfiedLinkError: InitDecoder
12-27 20:32:51.698: E/AndroidRuntime(11589): at com.xx.xxx.media.H264Decoder.InitDecoder(Native Method)
12-27 20:32:51.698: E/AndroidRuntime(11589): at com.xx.xxx.media.VideoParseThread.getH264(VideoParseThread.java:131)
12-27 20:32:51.698: E/AndroidRuntime(11589): at com.xxx.xxx.media.VideoParseThread.run(VideoParseThread.java:46)
Now when the application run the code that need the so library, it crashed. I have read some answers, but it's still not resolved.
If the all the library b project is in the project A, it worked well.
Any help will be appreciated, this problem drives me crazy, i know it should have one solution, but i don't know how.
First:
Horrible explaination of your project and description of your project structure.
Second:
Make sure it is exported in your build settings.
If you explain more precise, how your structure is, maybe with Screenshots, then I can narrow down my explanation of your mistake
Edit:
Under your "project properties" go into "java build path" and then "order and export".
In here your project needs to be present and marked.

NoClassDefFoundError When Debug Android Engine Connected Android Project

I’m struggling on a problem on my new Android C2DM test project:
Android Engine Connected Android Project.
The problem is:
At LogCat:
04-04 19:35:09.414: E/AndroidRuntime(320): java.lang.NoClassDefFoundError:
com.google.android.c2dm.C2DMessaging
Location at debug window: InvocationTargetException.class
InvocationTargetException.(Thrownable) Line 50
Exception: NoClassDefFoundError
Does any one have any idea what file (and where) I’m missing and how to fix?
Know where/how to get Google API source for debugging?
Really appreciate your inputs.
The problem is that the latest ADT doesn't allow libraries (.jar) in any other folder except "libs" so please rename the folder from "lib" to "libs" and then add the existing three libraries (.jar) again.

Categories

Resources