I'd like to import (and use) the Google Play Services library into an existing Android project, but I am struggling with what must be a dependency problem.
All documentation written by google is based upon Eclipse. We use IntelliJ IDEA.
Things I know:
I know how to import Modules, Libraries, add Dependencies, etc. in IntelliJ.
I also know that according to the getting started guide at Google, you have to add the google-play-services-lib into (Eclipse) as a project (by importing existing code into the workspace), and that you can do this in IntelliJ by adding a new module from existing code. It's the same procedure, different name.
I also understand what the Order and Export tab does in Eclipse (IntelliJ does it too).
Things I've done:
I copied (for safety) the google-play-services_lib folder from the Android SDK to my project root. So I have /myprj and /google-play-services_lib at the same level (I also have /facebooksdk and /actionbarsherlock at the same level) and proceeded to "Import Module" (from existing source). Then clicked next next next… (it worked, it was recognized).
The project structure looks like this (name intentionally blurred):
This correctly added a module (as you can see in the above screenshot). Now I need to add the dependency so my main project knows about this. I go to my modules and in the list, select my main module and then dependencies tab. I can see a few libraries (Joda time, android-query, gson, etc.) and two modules: FacebookSDK and actionbarsherlock. So far so good. And this is when things get weird.
Dependencies I've tried to add.
NOTE: In most cases I tried checking and unchecking the export checkbox and also tried adding this to the sherlockbar module at the same time, just for testing. I know these are a lot of combinations, but oh well.
1) Add a Jar or directory (knowing this was wrong, I tried). and pointed to the .jar that is inside the google play module /libs, named: google-play-services.jar.
2) Add a Library (and then adding it to the project(s))
3) Add the Module Dependency, (while having my main project selected). This shows you a pop-up like this:
PROBLEM
Even tho I can reference a PlusClient and I get the right imports, when I try to add a SignInButton in my layout xml, I get an error.
There's no point in pasting the whole XML Layout because it doesn't have anything strange, it's just a RelativeLayout with a few textviews. I added the g+ button like this:
<com.google.android.gms.common.SignInButton
android:id="#+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/logo_login"
android:layout_marginBottom="30dip" />
Just like Google says.
The first sign that something may be out of order is the fact that IntelliJ warnings you that the element is "not valid here", but I assume that's a limitation of the visual designer rather than a real problem.
However, when I run the project, I get this:
07-30 17:50:44.854: ERROR/ActivityThread(22324): Failed to inflate
android.view.InflateException: Binary XML file line #22: Error inflating class com.google.android.gms.common.SignInButton
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:134)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:262)
at com.myapp.ui.activities.LoginSignupActivity.onCreate(LoginSignupActivity.java:64)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
at android.app.ActivityThread.access$600(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4575)
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:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:586)
... 24 more
Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.R$drawable
at com.google.android.gms.internal.aa.b(Unknown Source)
at com.google.android.gms.internal.aa.a(Unknown Source)
at com.google.android.gms.common.SignInButton.c(Unknown Source)
at com.google.android.gms.common.SignInButton.d(Unknown Source)
at com.google.android.gms.common.SignInButton.setStyle(Unknown Source)
at com.google.android.gms.common.SignInButton.<init>(Unknown Source)
at com.google.android.gms.common.SignInButton.<init>(Unknown Source)
... 27 more
Here is the line that gets my attention:
Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.R$drawable
The next exception below is:
07-30 17:50:44.870: ERROR/AndroidRuntime(22324): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.ui.activities.LoginSignupActivity}: android.view.InflateException: Binary XML file line #22: Error inflating class com.google.android.gms.common.SignInButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2079)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
at android.app.ActivityThread.access$600(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4575)
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:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class com.google.android.gms.common.SignInButton
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:134)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:262)
at com.myapp.ui.activities.LoginSignupActivity.onCreate(LoginSignupActivity.java:64)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:586)
... 24 more
Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.R$drawable
at com.google.android.gms.internal.aa.b(Unknown Source)
at com.google.android.gms.internal.aa.a(Unknown Source)
at com.google.android.gms.common.SignInButton.c(Unknown Source)
at com.google.android.gms.common.SignInButton.d(Unknown Source)
at com.google.android.gms.common.SignInButton.setStyle(Unknown Source)
at com.google.android.gms.common.SignInButton.<init>(Unknown Source)
at com.google.android.gms.common.SignInButton.<init>(Unknown Source)
... 27 more
If I remove the code from the Layout, it works.
My idea is that this has to do with the way Android handles the R(esources) and therefore it may not be finding the resource for the button.
Has anybody managed to use: Intellij Idea (12+) with ActionbarSherlock and Google+ Library?
If so, how? :)
For historical reasons, I'm going to reproduce what I did, taken from here. Many thanks to #Hesam who found it. I will vote to close the whole question.
Note: the shortcuts are for OS X and Intellij 12 and 13.
Make sure you have the latest SDK/ADT Tools and the play services. They change every now and then and are usually not backwards compatible.
UPDATE I had to do this again, so this is the polished version of what I did.
You need to have a copy (as opposed to using it directly from the SDK folder), because if Google updates it, things are going to break when you update your SDK, it's safer to keep a copy (albeit more tedious because you will have to manually update when a new version comes out). I found out that it's better to decide when to update than to be surprised with cryptic compilation errors.
With that in mind, copy the library alongside your project. You should have a folder structure that looks like:
/something/yourmainmodule/
/something/any_other_module/
/something/modules.xml
/something/README.md (if you use github) :)
The library is located in
"ANDROID-SDK"/extras/google/google_play_services/libproject/google-play-services_lib
ANDROID-SDK is wherever you stored the SDK when you downloaded it. Google changes this every now and then, so just find it, it will be there.
Copy that entire folder so your project now looks like this:
/something/yourmainmodule/
/something/any_other_module/
/something/google-play-services_lib/ <-- THIS IS THE NEW ONE
/something/modules.xml
/something/README.md
Good, now let's import it to IntelliJ-IDEA the right way:
1) Select your project/main module from project panel (⌘ 1) and hit ⌘ ↓ in order to open project structure window or just do File -> Project Structure.
2) Select Modules from left panel, then hit + button (or ⌘ N) then select "import module" and navigate to the google-play-services_lib that you just copied next to your project's module folder. (/something/).
The wizard will ask a series of questions, just hit next, defaults are fine, but read what's going on, understand what's happening, this is a core concept in Java, Android and Intellij. Experiment if you don't know what each dialog is saying (or why some may be empty).
After you're done, the google play Project will be added to Modules alongside with your project.
Don't close this window (or open it again if you did).
3) Still in the modules, select your project/module, then select "Dependencies" from right panel (it's a tab) and finally Click + button at the bottom (or ⌘ N which will work if you have the focus in this tab), then from the popup chose "3 Module dependencies..." and select "google-play-services_lib", which you added in the previous step. It should be there. If it's not, you didn't add the module in step 2.
4) Finally, Click + button again (or ⌘ N) but this time select "1 jars or directories...", navigate to the "/libs" folder of the above path and select "google-play-services.jar".
5) Click ok and close project structure window.
If you did this, your main module should have a dependency that looks like this:
Also make sure that in the Project Structure window, FACETS Tab, the Google Play Services has the "Library Module" checked. It is a library module.
Note: Make sure you have not added "google-play-services_lib" project as library in "Libraries" (left panel under Modules). If you have, you can go to "Libraries and simply remove it. Google Play Library Should Not Appear In Libraries.
Credit: this text comes from this StackOverflow answer
Related
I;m not sure why but the Google play version of my app crashes upon opening when the normal apk doesn't. looking at the logcat sent back by a crash report it seems like it cant find the splash-screen class. which is weird. i have not touched the splash screen at all and the app worked before when got of google play.
i changed the version number from version 1 to version 2 since i couldn't have the same version number but would that be why it doesnt work?
here is the logcat from the crash report. i cannot duplicate this error when testing it in debug mode
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.LEEADS/com.LEEADS.timestableseasy.Splashscreen}: java.lang.ClassNotFoundException: Didn't find class "com.LEEADS.timestableseasy.Splashscreen" on path: DexPathList[[zip file "/data/app/com.LEEADS-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.LEEADS-1, /vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2192)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
at android.app.ActivityThread.access$600(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:5225)
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:741)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.LEEADS.timestableseasy.Splashscreen" on path: DexPathList[[zip file "/data/app/com.LEEADS-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.LEEADS-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.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2183)
... 11 more
You use Proguard? Except from obfuscation all method's name that you call in invoke()
For example add to proguard.cfg:
-keep class com.mypackagename.myActivity {
public static void myMethod( boolean, java.lang.String);
}
You must correct insert all parameters in method
FYI, an APK will act the same coming from teh Play store as if you deployed directly from your IDE or computer.
The Play store doesn't modify, add, or remove anything from your packaged app (APK). In other words, the APK downloaded from the Play store is identical to the one you uploaded from your computer.
Having said that, I think you have not exported your libraries with you APK. Looks like you have a library with LEEADS in it.
To fix this:
1. Right click on your project
2. Click 'Properties'
3. Click 'Java Build Path'
4. Select 'Order and Export' Tab
5. Make sure there is a check-mark next to 'Android Private Libraries'
I'd like to import (and use) the Google Play Services library into an existing Android project, but I am struggling with what must be a dependency problem.
All documentation written by google is based upon Eclipse. We use IntelliJ IDEA.
Things I know:
I know how to import Modules, Libraries, add Dependencies, etc. in IntelliJ.
I also know that according to the getting started guide at Google, you have to add the google-play-services-lib into (Eclipse) as a project (by importing existing code into the workspace), and that you can do this in IntelliJ by adding a new module from existing code. It's the same procedure, different name.
I also understand what the Order and Export tab does in Eclipse (IntelliJ does it too).
Things I've done:
I copied (for safety) the google-play-services_lib folder from the Android SDK to my project root. So I have /myprj and /google-play-services_lib at the same level (I also have /facebooksdk and /actionbarsherlock at the same level) and proceeded to "Import Module" (from existing source). Then clicked next next next… (it worked, it was recognized).
The project structure looks like this (name intentionally blurred):
This correctly added a module (as you can see in the above screenshot). Now I need to add the dependency so my main project knows about this. I go to my modules and in the list, select my main module and then dependencies tab. I can see a few libraries (Joda time, android-query, gson, etc.) and two modules: FacebookSDK and actionbarsherlock. So far so good. And this is when things get weird.
Dependencies I've tried to add.
NOTE: In most cases I tried checking and unchecking the export checkbox and also tried adding this to the sherlockbar module at the same time, just for testing. I know these are a lot of combinations, but oh well.
1) Add a Jar or directory (knowing this was wrong, I tried). and pointed to the .jar that is inside the google play module /libs, named: google-play-services.jar.
2) Add a Library (and then adding it to the project(s))
3) Add the Module Dependency, (while having my main project selected). This shows you a pop-up like this:
PROBLEM
Even tho I can reference a PlusClient and I get the right imports, when I try to add a SignInButton in my layout xml, I get an error.
There's no point in pasting the whole XML Layout because it doesn't have anything strange, it's just a RelativeLayout with a few textviews. I added the g+ button like this:
<com.google.android.gms.common.SignInButton
android:id="#+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/logo_login"
android:layout_marginBottom="30dip" />
Just like Google says.
The first sign that something may be out of order is the fact that IntelliJ warnings you that the element is "not valid here", but I assume that's a limitation of the visual designer rather than a real problem.
However, when I run the project, I get this:
07-30 17:50:44.854: ERROR/ActivityThread(22324): Failed to inflate
android.view.InflateException: Binary XML file line #22: Error inflating class com.google.android.gms.common.SignInButton
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:134)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:262)
at com.myapp.ui.activities.LoginSignupActivity.onCreate(LoginSignupActivity.java:64)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
at android.app.ActivityThread.access$600(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4575)
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:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:586)
... 24 more
Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.R$drawable
at com.google.android.gms.internal.aa.b(Unknown Source)
at com.google.android.gms.internal.aa.a(Unknown Source)
at com.google.android.gms.common.SignInButton.c(Unknown Source)
at com.google.android.gms.common.SignInButton.d(Unknown Source)
at com.google.android.gms.common.SignInButton.setStyle(Unknown Source)
at com.google.android.gms.common.SignInButton.<init>(Unknown Source)
at com.google.android.gms.common.SignInButton.<init>(Unknown Source)
... 27 more
Here is the line that gets my attention:
Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.R$drawable
The next exception below is:
07-30 17:50:44.870: ERROR/AndroidRuntime(22324): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.ui.activities.LoginSignupActivity}: android.view.InflateException: Binary XML file line #22: Error inflating class com.google.android.gms.common.SignInButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2079)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
at android.app.ActivityThread.access$600(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4575)
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:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class com.google.android.gms.common.SignInButton
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:134)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:262)
at com.myapp.ui.activities.LoginSignupActivity.onCreate(LoginSignupActivity.java:64)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:586)
... 24 more
Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.R$drawable
at com.google.android.gms.internal.aa.b(Unknown Source)
at com.google.android.gms.internal.aa.a(Unknown Source)
at com.google.android.gms.common.SignInButton.c(Unknown Source)
at com.google.android.gms.common.SignInButton.d(Unknown Source)
at com.google.android.gms.common.SignInButton.setStyle(Unknown Source)
at com.google.android.gms.common.SignInButton.<init>(Unknown Source)
at com.google.android.gms.common.SignInButton.<init>(Unknown Source)
... 27 more
If I remove the code from the Layout, it works.
My idea is that this has to do with the way Android handles the R(esources) and therefore it may not be finding the resource for the button.
Has anybody managed to use: Intellij Idea (12+) with ActionbarSherlock and Google+ Library?
If so, how? :)
For historical reasons, I'm going to reproduce what I did, taken from here. Many thanks to #Hesam who found it. I will vote to close the whole question.
Note: the shortcuts are for OS X and Intellij 12 and 13.
Make sure you have the latest SDK/ADT Tools and the play services. They change every now and then and are usually not backwards compatible.
UPDATE I had to do this again, so this is the polished version of what I did.
You need to have a copy (as opposed to using it directly from the SDK folder), because if Google updates it, things are going to break when you update your SDK, it's safer to keep a copy (albeit more tedious because you will have to manually update when a new version comes out). I found out that it's better to decide when to update than to be surprised with cryptic compilation errors.
With that in mind, copy the library alongside your project. You should have a folder structure that looks like:
/something/yourmainmodule/
/something/any_other_module/
/something/modules.xml
/something/README.md (if you use github) :)
The library is located in
"ANDROID-SDK"/extras/google/google_play_services/libproject/google-play-services_lib
ANDROID-SDK is wherever you stored the SDK when you downloaded it. Google changes this every now and then, so just find it, it will be there.
Copy that entire folder so your project now looks like this:
/something/yourmainmodule/
/something/any_other_module/
/something/google-play-services_lib/ <-- THIS IS THE NEW ONE
/something/modules.xml
/something/README.md
Good, now let's import it to IntelliJ-IDEA the right way:
1) Select your project/main module from project panel (⌘ 1) and hit ⌘ ↓ in order to open project structure window or just do File -> Project Structure.
2) Select Modules from left panel, then hit + button (or ⌘ N) then select "import module" and navigate to the google-play-services_lib that you just copied next to your project's module folder. (/something/).
The wizard will ask a series of questions, just hit next, defaults are fine, but read what's going on, understand what's happening, this is a core concept in Java, Android and Intellij. Experiment if you don't know what each dialog is saying (or why some may be empty).
After you're done, the google play Project will be added to Modules alongside with your project.
Don't close this window (or open it again if you did).
3) Still in the modules, select your project/module, then select "Dependencies" from right panel (it's a tab) and finally Click + button at the bottom (or ⌘ N which will work if you have the focus in this tab), then from the popup chose "3 Module dependencies..." and select "google-play-services_lib", which you added in the previous step. It should be there. If it's not, you didn't add the module in step 2.
4) Finally, Click + button again (or ⌘ N) but this time select "1 jars or directories...", navigate to the "/libs" folder of the above path and select "google-play-services.jar".
5) Click ok and close project structure window.
If you did this, your main module should have a dependency that looks like this:
Also make sure that in the Project Structure window, FACETS Tab, the Google Play Services has the "Library Module" checked. It is a library module.
Note: Make sure you have not added "google-play-services_lib" project as library in "Libraries" (left panel under Modules). If you have, you can go to "Libraries and simply remove it. Google Play Library Should Not Appear In Libraries.
Credit: this text comes from this StackOverflow answer
I've got a problem involving ClassNotFoundException. When i "Run as android application" from eclipse it works fine, but when i download it from Google Play (same source code but "Exported as signed app") it crashes with the following stacktrace:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.larphoid.aeboing/com.larphoid.aeboing.BoingBoing}: java.lang.ClassNotFoundException: com.larphoid.aeboing.BoingBoing in loader dalvik.system.PathClassLoader[/data/app/com.larphoid.aeboing-1.apk]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2703)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
at android.app.ActivityThread.access$2300(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4914)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.larphoid.aeboing.BoingBoing in loader dalvik.system.PathClassLoader[/data/app/com.larphoid.aeboing-1.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at android.app.Instrumentation.newActivity(Instrumentation.java:1033)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2695)
... 11 more
I've never had this problem before, and i'm not experienced yet in "reading" Stacktraces, so i'm pretty much puzzled at this. If anyone has some pointers or solution i'd appreciate it.
Thanks.
Gonna copy this from another question as I had the exact same problem before, and this is how I fixed it:
If you're running adt rev 22, you might not be exporting your libraries. I don't know why
Google did this exactly, but in the newest revolution you have to
check to make sure you're exporting your libraries yourself.
Right click your project, click Properties, and check Order & Export
under Java Build Path. It should look like this if you want to export
everything:
Afterwards, rebuild the application and export it again. It should be working now. To test, simply install the .apk to your phone manually before putting it on the store to make sure it works.
ClassNotFoundException indicates that something is missing on the classpath. Maybe you are missing a library in the classpath.
As the name suggests classNotFoundException in Java is a subclass of java.lang.Exception and Comes when Java Virtual Machine tries to load a particular class and doesn't found the requested class in classpath.
Maybe you change your package name while signing your apk.
Check your package and class name
I built my android project from command line and compile using ant debug install. But after i import a external project called Android-PullToRefresh to my project, my project becomes abnormal when running. Sometimes after i add a new id or delete a id in xml layout file, and my compile goes well but when the app starting to run, it throws a ClassCastException.
When it happens i can only use ant clean && ant debug install to fix it. But recompile a hole project costs double time, i don't wish to compile a project for one minute or more. So can i do some trick to make this error won't happen again?
Stack trace:
E/AndroidRuntime(21226): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zhangdan.preferential/com.zhangdan.preferential.RecommendActivity}: java.lang.ClassCastException: android.widget.TextView cannot be cast to com.handmark.pulltorefresh.library.PullToRefreshListView
E/AndroidRuntime(21226): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
E/AndroidRuntime(21226): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
E/AndroidRuntime(21226): at android.app.ActivityThread.access$600(ActivityThread.java:142)
E/AndroidRuntime(21226): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
E/AndroidRuntime(21226): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(21226): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(21226): at android.app.ActivityThread.main(ActivityThread.java:4931)
E/AndroidRuntime(21226): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(21226): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(21226): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
E/AndroidRuntime(21226): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
E/AndroidRuntime(21226): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(21226): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to com.handmark.pulltorefresh.library.PullToRefreshListView
E/AndroidRuntime(21226): at com.zhangdan.preferential.RecommendActivity.findViews(RecommendActivity.java:65)
E/AndroidRuntime(21226): at com.zhangdan.preferential.RecommendActivity.onCreate(RecommendActivity.java:58)
E/AndroidRuntime(21226): at android.app.Activity.performCreate(Activity.java:5008)
E/AndroidRuntime(21226): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
E/AndroidRuntime(21226): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
E/AndroidRuntime(21226): ... 11 more
W/ActivityManager( 380):
RecommendActivity.java:
64 private void findViews() {
65 mFakeListView = (PullToRefreshListView)findViewById(R.id.refreshable_list);
66 mListView = mFakeListView.getRefreshableView();
67 }
xml:
1 <?xml version="1.0" encoding="utf-8"?>
2 <com.handmark.pulltorefresh.library.PullToRefreshListView
3 xmlns:android="http://schemas.android.com/apk/res/android"
4 xmlns:ptr="http://schemas.android.com/apk/res-auto"
5 android:id="#+id/refreshable_list"
6 android:layout_width="fill_parent"
7 android:layout_height="fill_parent"
8 android:cacheColorHint="#00000000"
9 android:fadingEdge="none"
10 android:listSelector="#android:color/transparent"
11 android:divider="#null"
12 android:paddingTop="5dip"
13 android:paddingBottom="5dip"
14 android:scrollbarStyle="outsideOverlay"
15 ptr:ptrMode="both" />
What seems to be happening is that whenever you add/delete a layout ID in your project, somehow the ant debug install command does not correctly rebuild all the affected code and causes an ID for another widget to be used in place of the correct value for R.id.refreshable_list, which in turn causes the ClassCastException when your app is started.
Here's my suggestions:
Check that all your files/folders have valid dates (maybe any of them are dated in the future?)
Update your build tools to the latest versions (Android SDK, ant, and so on).
What IDE are you using? Check to see if it has automatic build enabled which might somehow interfere with your command line build.
Hope this helps!
When it happens i can only use ant clean && ant debug install to fix it. But recompile a hole project costs double time, i don't wish to compile a project for one minute or more.
Running ant clean debug install may be incrementally faster than running those operations separately.
You can also try modifying your Ant script to delete the R.class files in your bin/classes/, rather than using the clean command. I haven't tried this beyond a quick test just now, because usually this isn't a problem with a reasonable-sized project and a decent development machine. However, the heart of Joe's answer is that the last-compiled R.class files are out of sync with the to-be-generated R.java files, and for whatever reason, Ant's dependency mechanism does not always pick this up. Deleting the R.class files yourself (e.g., find bin/classes -name R.class | xargs rm on Linux) allows you to avoid clean and having to rebuild everything that clean wipes out, yet it will force a fresh recompile of the R.java classes. And, in very light testing, this appears to work, insofar as the resulting built APK works. As the saying goes, your mileage may vary.
Note that if you are using Android library projects -- like Pull-to-Refresh, there will be multiple R.class files (one for your app, one per library).
Sometimes resource's errors can not seen. You should be sure that there isnt any error in your xmls. (com.handmark.pulltorefresh.library.PullToRefreshListView is right package?)
After you can try
1) delete your R Class
2) Clean project
3) fix project properties
4) rebuild.
We have very weird java.lang.ClassNotFoundException on app startup that happens to very small amount of customers (< 1%). We never saw it in dev env and we cannot understand the source of this issue. Here is the stack trace from Google play crash reports.
java.lang.RuntimeException: Unable to instantiate application com.mycompany.myapplication.MyApplication: java.lang.ClassNotFoundException: com.mycompany.myapplication.MyApplication in loader dalvik.system.PathClassLoader[/mnt/asec/com.mycompany.myapplication-1/pkg.apk]
at android.app.LoadedApk.makeApplication(LoadedApk.java:490)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3784)
at android.app.ActivityThread.access$2200(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1082)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4268)
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:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.mycompany.myapplication.MyApplication in loader dalvik.system.PathClassLoader[/mnt/asec/com.mycompany.myapplication-1/pkg.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at android.app.Instrumentation.newApplication(Instrumentation.java:972)
at android.app.LoadedApk.makeApplication(LoadedApk.java:481)
... 11 more
If the issue only occurs on with signed APKs and you are using Eclipse to Export the Signed APK ...
Before you 'Export and sign an APK' in Eclipse turn off the following setting in the menu [Project > Build Automatically] (then can switch it back on later when you continue developing).
I recently deployed an update to my app, and a user reported a crash the very next day via the Google Play reporting facility. The stack dump was for LoadApk() and the error was in the loading of my Application class. Here is that dump:
java.lang.RuntimeException: Unable to instantiate application com.goalstate.WordGames.FullBoard.library.FullBoardApplication: java.lang.ClassNotFoundException: Didn't find class "com.goalstate.WordGames.FullBoard.library.FullBoardApplication" on path: DexPathList[[],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:516)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4703)
at android.app.ActivityThread.access$1600(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
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:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.goalstate.WordGames.FullBoard.library.FullBoardApplication" on path: DexPathList[[],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newApplication(Instrumentation.java:981)
at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
... 11 more
I have a library and my Application class was defined in that library. The manifest for my app (which used the library) referred to the class in that library by its full path. It did not have an application class of its own.
All of my in-house testing had not reproduced this problem, and even when I tested (using the Samsung Remote Test Lab) on the same device (actually two different devices, one running 4.3 and one running 4.4.4) as reported the crash (a Galaxy Note II, running Android 4.4), there was no problem.
In searching for information on this I found mention of the fact that different devices may have slightly different approaches to resolving class references, and that is probably why most devices had no problem with my APK, but this particular device (which, unlike my test devices, was provided with its Android flavor by Sprint) did. And similarly, it may be why just one percent of your own customers had the problem, while most did not.
I decided that the best approach would be to make it as easy as possible for even an unsophisticated device to find the classes that were referenced from my manifest file. So, I defined a new application class within the package of the app itself (rather than the library) and I had that class inherit from the application class in my library. The new class was otherwise empty.
I then replaced the full path reference to the application class in the library with a relative reference to the new class I had created in the app itself. So, instead of having:
<application android:name="com.goalstate.WordGames.FullBoard.library.FullBoardApplication"
in my manifest, I had:
<application android:name=".FullBoardWordChumsApplication"
That (according to folklore on this topic) should make it easier for a less sophisticated resolution process to succeed.
I also took the full path that I had been using in the manifest to name my already-local activity class and made it relative (by simply lopping off everything preceding the final dot).
Additional folklore found online indicates that it may help to turn off "Build Automatically" for the project in Eclipse, then exit Eclipse, re-enter Eclipse, and then, after it rebuilds, go directly to Android Tools to export the signed APK (without ever turning on Build Automatically). So, throwing salt over my left shoulder, and saying a prayer to the gods of fragmentation paranoia, I accommodated this superstition in preparing my APK for release.
Does any of this really help? Time will tell, but so far my updated release has not generated any additional crashes.
This Error occurs when in your manifest file in application tag whatever class name you put it is not match with your coding java file .So make a current both in way.