I have an Android project with an NDK/JNI library in Eclipse Ganymede. Inexplicably, the bin folder contains a copy of all my C++ sources from the jni folder. So does the APK, if you rename it to ZIP and examine. If I delete those files from bin, then clean and rebuild, they're there again. What going on, please? I have no intention of distributing the sources along with the app.
Kinda resolved. For some reason, jni was listed in project properties under "Java build path". Once I've removed that, it was fine. No sure how did this condition come to be.
Related
I've been trying to solve a problem about Android build, but couldn't figure out how to solve it.
Basically, I am trying to build an Android project using Gradle. It works perfect, but the size of the final apk is 7MB more than when I builded with Eclipse.
When I unzip the apk, I see that the JNI Libs are included twice. Which is different from the Eclipse build that includes it only one time. Here is the paths I can find them in the APK:
lib/armeabi
lib/armeabi-v7a
main/jniLibs/armeabi
main/jniLibs/armeabi-v7a
In my project, those two files are in:
android/app/src/main/jniLibs/armeabi
android/app/src/main/jniLibs/armeabi-v7a
I have two different build.graddle files in:
android/
android/app/
None of them contains anything related to the JNI Libs.
To build a release, I use the command:
./gradlew assembleRelease
And everything works fine. I use Gradle 1.10.
I was wondering if someone ever encountered the problem and find a solution to avoid to the JNI Libs to be included twice in the APK.
Thanks :)
Put .so files in...
/src/main/jniLibs/armeabi-v7a
/src/main/jniLibs/x86
directories and gradle will correctly package the .so files into the correct app and it won't include the duplicates
This is a good reference..
http://www.shaneenishry.com/blog/2014/08/17/ndk-with-android-studio/
There are tons of questions about this, but none gives a clear solution to this problem (is it really so difficult?)
I'm trying to add a jar to my Android project. Since r17, Google says we should add the jars to /libs folder, and that the andriod tools will take care of the rest.
I have included a very big library, and it works good, except of one class, so I decided to try and make my own jar.
I created a new java project, and added a simple Test class. Then I exported it as a jar and manually copied the jar into the /libs folder. I cleaned and rebuilt my android app without problems, but at runtime, referencing the Test class, i get the following errors:
java.lang.NoClassDefFoundError: mytestpackage.Test
When I include the source of the jar into my project directly, it works (of course).
So what am I doing wrong?
Since r17, Google says we should add the jars to /libs folder, and that the andriod tools will take care of the rest.
Correct.
So what am I doing wrong?
If I had to guess, in addition to copying the JAR to libs/, you also did "Add to Build Path" in Eclipse (per the other answer). Not only is that not necessary, but reports indicate that doing this somehow suppresses actually packaging the JAR from libs/ into the APK. If indeed you did this, undo the manual build path change, and see if that helps.
Well, after struggling with it for a day now, I found out that I had the compiler level set to 1.7 in the library project, so when I exported the jar, it was exported with a higher compiling level than what android supports (1.6).
So the solution, in the project of the jar to export:
Properties -> Java Compiler -> Enable specific settings -> Compiler compilance level -> 1.6
That fixed it for me, I hope it's useful.
You need to update your .classpath. In Eclipse, mark the library (put in /libs) and Right click->Build Path->Add to build path
I am using a thirdparty jar file in my android project. When I add the jar to the build paths, via eclipse project -> properties -> java build path -> Libraries -> add external jar.
The project compiles fine until that line of code runs which uses any class from that jar and I get class not found exception at runtime and the program crashes.
I solved it by copying the third party jar file to the libs folder of my project. The class not found exception goes away.
Question:
Can someone please shed some light why this is required and why does it not just work with a reference from the project properties despite the fact it compiles fine.. Why do I have to explicitly copy it to libs folder ?
When I add the jar to the build paths, via eclipse project -> properties -> java build path -> Libraries -> add external jar.
That is not the proper procedure for use with the Android build tools.
I solved it by copying the third party jar file to the libs folder of my project. The class not found exception goes away.
Correct.
Can someone please shed some light why this is required and why does it not just work with a reference from the project properties despite the fact it compiles fine.. Why do I have to explicitly copy it to libs folder ?
Because only the JARs in libs/ are added to the APK file. The Java build path is pure a compile-time thing, not tied into Android's packaging of APK files.
All the libraries in the folder “libs” are found by the Android Eclipse plugin and are added to the “Android Dependencies” item of the project. A better illustration here
:http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17
I maintain an Android app and am not using Eclipse. I am not using Eclipse. I am using ant and build.xml and build.properties.
I have places my .jar file into the libs/ directory. My code compiles just dandy. But when I run it on the emulator, the output APK does not include the .jar, so I get a runtime stacktrace:
ERROR/AndroidRuntime(470): java.lang.NoClassDefFoundError: com.google.ads.AdView
my build.properties looks like this:
jar.libs.dir=libs
And the libs/ directory contains my .jar file.
What needs to be in build.xml so that the external .jar file is included in the APK?
Edit: In theory this answer should work, but it doesn't for me. Is it out of date? What gives? How to add external jar libraries to an android project from the command line
I just came over a similar problem and noticed that libraries should not be placed in "myprojectdir\lib". When I moved them to "myprojectdir\libs" everything started to work.
It turns out that I needed to upgrade the version of ant I was using to 1.8. During the compile process, I had been getting this error message:
Warning: Reference out.dex.jar.input.ref has not been set at runtime,
but was found duringbuild file parsing, attempting to resolve. Future
versions of Ant may support referencing ids defined in non-executed
targets.
I googled it, and found that I needed to upgrade Ant, and now I don't get this warning, and my application does not force close.
What needs to be in build.xml so that the external .jar file is included in the APK?
Just putting it in libs/ is sufficient.
my build.properties looks like this:
That line should not be necessary. It does not appear in my build.properties files that build successfully with JAR files.
If you use dexdump -f classes.dex from your project's bin/ directory, you will be able to determine whether com.google.ads.AdView made it in there. If it did not, then something is strange with your build scripts. If it did, then perhaps there is a dependent JAR that you are missing (though I would expect a VerifyError in that case).
You use 3rd party library, but you seem didn't run DX on it. Make sure that not only your code processed by DX tool (I assume Ant does it), but also all 3rd party libraries you use. You can look in 7Bee script I use to convert web applications to Android davlik format, so it can work for you too. You can find more about the script on Atjeews page.
Solution:
right click on the project in project tree and select Project
properties
select Java Build Path
select TAB Order
and Export
check GoogleAdMobAdsSdk-4.0.4.jar (or your
version SDK)
press OK
clean project by menu Project
-> Clean
rebuild project (Project – Build Automatically)
I have built a dynamic library in android using android build system. This library provides jni interface for functions inside it. Now I want to include this library in an application (.apk). I am using eclipse for application development. Now, how can I use the prebuild dynamice library (.so) in my application ? I tried putting it in a lib folder in my application but it is not working.
Any pointers are appreciated.
I am not using ndk to build my .so.
Since you write 'so' I think you're using NDK. If you're using NDK I don't know the answer.
If you're using the "Java" SDK, then in your library project go to Properties -> Android, and Check "Is Library". In your "apk" project, go to Properties -> Android -> Add . And your Library project should be available.
Also, any Library added in the "Java Build Path" Menu (again, in project properties) should be available in the APK in the end.
I know it's slightly old, but have you checked in the built APK to see if your .so library is there? Should be in the libs/armeabi folder.
Also, your .so file should be in lib/armeabi folder in your eclipse solution. I'm guessing the armeabi bit depends on which processor your .so file is build for.
Also, I know that if your library isn't called lib[name].so, it won't get copied when the apk is installed on the device. So:
libfoo.so copies
foo.so doesn't copy
foo.so doesn't copy
Also, you can use DDMS (its a view in eclipse) and it's file explorer to see if it's been copied to your device. It should be under data/data/[packagename]/lib.
Hope this helps a bit!
Andy.
I hit this same problem while building Qiqqa for Android. Under your eclipse android project, make sure you have a libs directory (not that it is plural libS not singular lib). Inside that create the armeabi/etc subdirs with their respectibe .so files.
Then when you build, eclipse will automatically pick up this libs directory and create the corresponding lib in your apk. System.loadLibrary("XXX") will then resolve to libXXX.so on your correct architecture...
Cheers,
Jimme