Adding ".so" library to my android studio project - java

I am having issues when i try to add a spatialite database to my android studio projet.I followed this tutorial https://www.gaia-gis.it/fossil/libspatialite/wiki?name=spatialite-android-tutorial , as mentioned i added two folders to my project :
the native spatialite libraries: they are places in a folder named libs in my App directory and contains several folders for different platforms that hold the main library, called libspatialite.so
the basic API classes, contained in the jsqlite package
Despite this ,i am getting this error :
11-13 13:52:17.358 1853-1853/liara.geodatamining W/System.err﹕ Unable to load sqlite_jni: java.lang.UnsatisfiedLinkError: Couldn't load proj from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/liara.geodatamining-2.apk"],nativeLibraryDirectories=[/data/app-lib/liara.geodatamining-2, /system/lib]]]: findLibrary returned null
11-13 13:52:17.358 1853-1853/liara.geodatamining W/dalvikvm﹕ No implementation found for native Ljsqlite/Database;.internal_init:()V
11-13 13:52:17.358 1853-1853/liara.geodatamining W/dalvikvm﹕ Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Ljsqlite/Database;
11-13 13:52:17.358 1853-1853/liara.geodatamining W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb2d19b20)
11-13 13:52:17.358 1853-1853/liara.geodatamining E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: liara.geodatamining, PID: 1853
java.lang.UnsatisfiedLinkError: Native method not found: jsqlite.Database.internal_init:()V
at jsqlite.Database.internal_init(Native Method)
at jsqlite.Database.<clinit>(Database.java:951)
at liara.geodatamining.map.onCreate(map.java:116)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Am i missing something ?

This sounds a lot like you haven't included the appropriate version of the NDK for your emulator. Per the Android docs, the following platforms support Android NDK
ARM
ARM-NEON
x86
MIPS
The most common by far for real devices is ARM (armeabi-v7a). In fact, it's probably almost no loss to not include anything except for this for a published build. But the emulators often work off of x86. I know I have a NDK file for x86 that I remove every time I'm ready to build for release, and re-add when I want to use my desktop emulator.

if you're only using .so files and not compiling any C/C++ sources yourself, you don't need the NDK.
With Android Studio, the place where you drop .so files isn't the same than with eclipse. Now it's inside jniLibs/<ABI> where ABI can be armeabi, armeabi-v7a, x86, x86_64, mips, mips64, arm64-v8a.
You can check that your .so files are properly integrated by opening your APK as a zip file and simply checking that your .so files are inside lib/<abi> folders.

Related

Android build variant debug gives java.lang.NoClassDefFoundError

I have been working on a project that has been perfectly fine, until i included the android-smack-xmpp library.
After this inclusion, i am not able to run the app on devices (API < 21) on debug mode. However i am able to run it on release build variant.
Process: com.example, PID: 496
java.lang.NoClassDefFoundError: com.example.network.ServerCalls$3
at com.example.network.ServerCalls.initData(ServerCalls.java:167)
at com.example.ui.fragmentsAndActivities.homeFeed.HomePageActivity.onCreate(HomePageActivity.java:212)
at android.app.Activity.performCreate(Activity.java:5248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
ServerCalls is included in the HomePageActivity, and compilation works just fine. What is that i could be missing here ?
Also HomePageActivity.java:212 is :
ServerCalls.samosaInitData()
Edit : I have been able to get it working my setting minifyEnabled and shrinkResources to true in gradle for the debug build. This is probably pointing at improper linking in the JVM. But this looks like a hack to me. Can somebody point me to a cleaner way of doing the same?
The error was multi-dexing the solution.
The smack-api library introduction led to the 64k dex limit to be exceeded.
Multidexing the solution does the trick.
It looks like you don't export your library in the final .apk file.
You have to choose the Compile option in your Android Studio project settings in the Dependencies section.

App works in debug but is crashing on google play version (classpath issue?)

I just posted a very major update to a program I have on google play. Everything works fine locally. But I have received field reports of about 20 or 30 of the following Crash report:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.twoplay.twoplayer/com.twoplay.twoplayer.TwoPlayer2Activity}: java.lang.ClassNotFoundException: com.twoplay.twoplayer.TwoPlayer2Activity in loader dalvik.system.PathClassLoader[/data/app/com.twoplay.twoplayer-1.apk]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1680)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
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)
Caused by: java.lang.ClassNotFoundException: com.twoplay.twoplayer.TwoPlayer2Activity in loader dalvik.system.PathClassLoader[/data/app/com.twoplay.twoplayer-1.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.newActivity(Instrumentation.java:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1672)
... 11 more
com.twoplay.twoplayer/com.twoplay.twoplayer.TwoPlayer2Activity is the correct name of the initial startup activity.
I also have a similar crash-dump where one of the app's services successfully starts, but crashes shortly after starting due to a missing class (not the service class itself).
I am using android.support.v4, along with a variety of other private libraries.
The project files have (for all practical purposes) been rebuilt from scratch since 2.0 upgrade. Although the package file name should be correct.
Curious things that I don't entirely understand in the log file:
/data/app/com.twoplay.twoplayer-1.apk
Why does "-1" get appended? The actual name of the APK seems to vary from crash dump to crash dump from the field. Sometimes the "-1" is there; sometimes not. e.g. (from other logs):
/data/app/com.twoplay.twoplayer-2.apk
I am assuming and hoping that Google Play developer console would not let me update my app if I had signed with an incorrect key. I didn't have any problems uploading.
Obviously, I'm not able to debug this locally, since I can't download my own app from Google Play. (I do hate that).
Any theories, or suggestions on how to approach gratefully appreciated.

google-play-services won't build into Android Maps HelloWorld project in Eclipse

UPDATE: A UI bug was preventing me from importing google-play-services_lib. I had to click immediately below the SDK list to be able to scroll to see the Library box. See the image in the accepted answer for more info.
I am using Android IDE to get a Hello World map app, which I have named Intactless2. The files are all named correctly, android-support-v4.jar in /libs, I have a valid API key, etc.
I followed Google's Android Maps guide, copying and pasting the Java and activity_main.xml verbatim:
https://developers.google.com/maps/documentation/android/start#getting_the_google_maps_android_api_v2
I correctly added everything there to my manifest. I got an error on <meta-data android:name="com.google.android.gms.version"... 's value being incorrect, so I hardcoded the integer from the version.xml file so that it's android:value="4030500". Otherwise my manifest is unchanged.
I tried all of the solutions in the top Google hits for the error messages I'm getting and it still won't run. Normally, this would indicate an idiosyncratic bug that I haven't thought about that might even be unrelated to Google Play Services, but I rebuilt it exactly as Google's guide suggests and redid all of the recommendations in those posts and still can't use Google Play Services.
I am running a 4.4 emulator and 4.4 is the minimum version my project will build to. I have tried the following to be able to use google-play-services/google-play-services_lib in my app:
1) Made an Eclipse project for Google Play Services and added it to my project. Right-click on my project -> Properties -> Java Build Path -> Projects Add -> google-play-services_lib.
a) Checked google-play-services_lib in Order & Export
b) Unchecked oogle-play-services_lib in Order and Export
2) Copy-pasted google-play-services, google-play-services_lib, and google-play-services.properties from my Android SDK directory to my /libs directory in my project.
1) Properties -> Android -> Target Build Path -> Android 4.4
2) Properties -> Android -> Target Build Path -> Google APIs (the one directly below "Android 4.4)
That's a lot of combinations including the solutions people on StackOverflow have suggested.
Also, if I add <uses-library android:name="com.google.android.gms.maps" /> (or remove the gms as some guides advise) to my manifest, I get this LogCat error:
11-13 00:57:18.890: E/PackageManager(938): Package com.example.intactless2 requires unavailable shared library com.google.android.gms.maps; failing!
Importing google-play-services/google-play-services_lib as an Eclipse project:
Screenshot of google-play-services_lib Eclipse project: http://postimg.org/image/ukbqjk9lp/
Screenshot of my hello world Maps project in Package Explorer: http://postimg.org/image/589t2137h/
Console output:
...
[2013-11-12 21:57:13 - Intactless2] Installing Intactless2.apk...
[2013-11-12 21:57:19 - Intactless2] Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY
[2013-11-12 21:57:19 - Intactless2] Please check logcat output for more details.
[2013-11-12 21:57:19 - Intactless2] Launch canceled!
LogCat:
11-13 01:03:44.870: E/AndroidRuntime(1886): FATAL EXCEPTION: main
11-13 01:03:44.870: E/AndroidRuntime(1886): Process: com.example.intactless2, PID: 1886
11-13 01:03:44.870: E/AndroidRuntime(1886): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.intactless2/com.example.intactless2.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
11-13 01:03:44.870: E/AndroidRuntime(1886): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
11-13 01:03:44.870: E/AndroidRuntime(1886): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
11-13 01:03:44.870: E/AndroidRuntime(1886): at android.app.ActivityThread.access$700(ActivityThread.java:135)
...
Putting google-play-services.jar, google-play-services_lib.jar, and google-play-services.jar.properties directly into my project's /libs directory
Screenshot of my hello world Maps project in Package Explorer: http://postimg.org/image/l68z4crl7/
Console output:
...
[2013-11-12 22:15:20 - Intactless2] Uploading Intactless2.apk onto device 'emulator-5554'
[2013-11-12 22:15:20 - Intactless2] Installing Intactless2.apk...
[2013-11-12 22:15:37 - Intactless2] Success!
[2013-11-12 22:15:37 - Intactless2] Starting activity com.example.intactless2.MainActivity on device emulator-5554
[2013-11-12 22:15:41 - Intactless2] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.intactless2/.MainActivity }
LogCat:
11-13 01:15:43.990: E/AndroidRuntime(1959): FATAL EXCEPTION: main
11-13 01:15:43.990: E/AndroidRuntime(1959): Process: com.example.intactless2, PID: 1959
11-13 01:15:43.990: E/AndroidRuntime(1959): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
11-13 01:15:43.990: E/AndroidRuntime(1959): at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
11-13 01:15:43.990: E/AndroidRuntime(1959): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
11-13 01:15:43.990: E/AndroidRuntime(1959): at android.app.Activity.onCreateView(Activity.java:4784)
11-13 01:15:43.990: E/AndroidRuntime(1959): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
11-13 01:15:43.990: E/AndroidRuntime(1959): at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
11-13 01:15:43.990: E/AndroidRuntime(1959): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
11-13 01:15:43.990: E/AndroidRuntime(1959): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
11-13 01:15:43.990: E/AndroidRuntime(1959): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
11-13 01:15:43.990: E/AndroidRuntime(1959): at android.app.Activity.setContentView(Activity.java:1928)
11-13 01:15:43.990: E/AndroidRuntime(1959): at com.example.intactless2.MainActivity.onCreate(MainActivity.java:11)
11-13 01:15:43.990: E/AndroidRuntime(1959): at android.app.Activity.performCreate(Activity.java:5243)
Thank you in advance! Any help is appreciated. :)
You mentioned you are using a 4.4 emulator - you need to use the Google APIs (Google Inc.) - API Level 19 emulator to test with Google Play Services.
I Think You have error in you XML file ,because in log-cat you are getting
Binary XML file line #2: Error inflating class fragment first you try to rectify it

resources not found - android

I have had my first errors come through via the developer console on a published app. The errors are:
java.lang.RuntimeException: Unable to start activity ComponentInfo{fetchfree.diss.ellis/fetchfree.diss.ellis.Intro}:
android.content.res.Resources$NotFoundException: Resource ID #0x7f030007
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
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:871)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030007
at android.content.res.Resources.getValue(Resources.java:892)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:1869)
at android.content.res.Resources.getLayout(Resources.java:731)
at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:210)
at android.app.Activity.setContentView(Activity.java:1647)
at fetchfree.diss.ellis.Intro.onCreate(Intro.java:47)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
... 11 more
The app is running fine on my devices (S2,S3,S4 and galaxy ace) and the emulator and have not been able to replicate this. The resources its referring to at #0x7f030007 is a layout file for my setContentView of the Intro activity.
Resources:
Layout-normal-hdpi
Layout-normal-mdpi
Layout-sw360dp
My manifest states:
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="false"
android:smallScreens="false" />
I've seen this happen generally because the version uploaded to the playstore would not match the release apk. Best way is to clean the project in eclipse, build, release and then upload the apk to the play store. If this still happens you can check for a few more things I've gathered while searching for a similar issue on SO
1.) Make sure that your imports are correct. R.java must be your local R.java and not Android.R . Do a check in all your files
2.) Make sure you are not passing integer values to Views.
For instance dont do this
int i = 5;
myTextView.setText(i);
But do this
myTextView.setText(String.valueOf(i));
I suspect this to be a problem with you , so scan your code for this type of errors.
The compiler will not complain.
3.) Use this way of declaration
android:id="#id/android:list"
rather than
android:id="#android:id/list"
for id declarations
Make these changes if any, clean, build and upload. Should work.

Android NoClassDefFoundError when run from Eclipse

So I have an app that has previously worked perfectly in Eclipse.
Since I have converted to Maven, I am getting NoClassDefFoundError when I try to start a particular activity (SliderMenuActivity).
The strange thing is that the app will start and load the main activity (StartActivity) which is the same package. Note that both activities are included in the AndroidManifest.xml
It seems that the offending piece of code is:
Intent intSliderActivity = new Intent(StartActivity.this, SliderMenuActivity.class);
Just wondering does the change to the src folder have anything to do with this?
I have also changed the source folder to look like src/main/java/com/conor/etc and updated the build path.
Any ideas on how to solve?
For reference, here is the stacktrace:
E/AndroidRuntime(25063): FATAL EXCEPTION: main
E/AndroidRuntime(25063): java.lang.NoClassDefFoundError: com.my_app.android.app.SliderMenuActivity
at com.my_app.android.app.StartActivity$6.my_appApiCallback(StartActivity.java:261)
at com.my_app.android.app.my_app_user_api.my_appApiTask.onPostExecute(my_appApiTask.java:129)
at com.my_app.android.app.my_app_user_api.my_appApiTask.onPostExecute(my_appApiTask.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:631)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
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)
declare your class in manifest file with package name like
<activity android:name="com.example.SliderMenuActivity">
I think you did not build success LeftMenuSide library. Please try to build again

Categories

Resources