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'
}
Related
So, I installed everything, linked the project folder and my app crashes when I try to check the services.
Any hoop I forgot to jump on this stupidly over-complicated system just to display a simple map with some markers on my app?
All I get is "07-06 20:01:43.132: E/AndroidRuntime(1348): Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.common.GooglePlayServicesUtil", even if I try to execute it inside a try-catch, it will still crash the app.
I've seen an app crash the same way before, but it only did because the google-play-services folder was added to the project in the Properties - Java Build Path section instead of including it as an android library in Properties - Android section.
Finnaly made this P.O.S work. Instead of doing all dumb crap googles tells you, just add a variable that points to their google-play-services.jar. But I think doing things simple is too mainstream for those hipsters.
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.
this is a copy of my question on Pubnub support page:
Hi all, I tried running the PubnubTestApp that is downloadable with the Pubnub API from your git repo.
but when I try and start the test app i firstly get a build path error because apparently you (pubnub guys) have configured the project to look for 2 jar files that don't exist. (bcprov-jdk16-145.jar and commons-codec-1.2.jar).
after I removed those 2 references the project showed no error. but when I tried running it, it crashed again with this error:
"07-04 12:29:11.782: E/AndroidRuntime(754): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.fbt/com.fbt.PubNubTestActivity}: java.lang.ClassNotFoundException: com.fbt.PubNubTestActivity in loader dalvik.system.PathClassLoader[/data/app/com.fbt-1.apk"
after looking over the internet for the reasons for this crash, I noticed that in the manifest.xml file in the project there is a mistake in the name of the activity name. (it's named ".PubNubTestActivity" instead of ".PubnubTestActivity").
after changing the manifest, everything works and the app will install and run but there a a few problems still.
when pressing the "publish" button or the "history" button the app crashes and dies automatically. also it crashed without any clicking of anything (just like that).
here are the crash reports I got from the emulator.
http://pastie.org/private/pojnpnxmznvn9azdg7uyg
apparently the project doesn't recognize the "pubnub.crypto" jar file even though I (and you) added it to the build path and made sure it's in the project.
please let me know how to fix this so I can use (at last) pubnub in my app.
Have you tried the latest build? This should be fixed now.
I am trying to run the sample app for the Bump API 3.0, when I try to run the application on the emulator i get the following error:
E/AndroidRuntime(742): java.lang.RuntimeException:
Unable to instantiate service com.bump.api.BumpAPI:
java.lang.ClassNotFoundException: com.bump.api.BumpAPI
I tried to follow the API instructions (I'm rather fresh as far as android/java/any programing goes), i added the attached .jar file to the project (build path-> add JARs), and i see the missing class inside it in the "refrences libraries" list. There's also a .so file attached, this one i only placed in "libs" folder as i'm not sure how to link it to the project besides that.
I would appreciate any help on resolving this,
Thanks a lot,
Geva Tal.
EDIT: Solved after creating a new AVD...still don't know what went wrong.
It sounds like everything should be working fine... I suggest cleaning your project, restarting eclipse, and perhaps creating a new AVD.
https://groups.google.com/forum/?fromgroups#!topic/bump-api-android/WMGHaRqoWQA
Here's the answer. Include .so into the libs folder of your project. Their instructions page is missing this.
My project got messed up so I started over by just cloning from my repo. After getting all dependencies in order, I tried running my app and it crashes from:
java.lang.RuntimeException: Unable to instantiate activity
java.lang.ClassNotFoundException: org.me.app.activities.Main in loader dalvik.system.PathClassLoader[/data/app/org.me-1.apk]
The class is there, its in the Manifest, everything is good. What can I do?! I feel like my app is burning in flames now!!
It looks like there are several possibilities that could have caused this.
Use of the android name attribute in the manifest, incorrect activity naming convention, .project file corruption, accidentally unchecking "Project -> Build Automatically": here
Incorrect (or inconsistent) package naming: here
Incorrect class loader context: here
Also you might find ideas on the Google Group thread.
Each of these has additional ideas and debugging attempts through the thread responses and comments.
If none of these work for you let us know and maybe we can find a new cause.