class not found error while trying to generate jni headers - android-ndk

why does every time i try to generate jni files, following error pops up?
I have tried specifying class path but it didn't help.

You need to go to classpath and run the command
Follow this guide :
http://www.ntu.edu.sg/home/ehchua/programming/android/android_ndk.html
-classpath: in our case, we need the JNIActivity.class which is kept in "< project-root >\bin\classes"; and its superclass
Android.app.Activity.class which is kept in android.jar under the
Android SDK.
The error is coming because the folder contains *.java files and we are looking for *.class files

Related

Could not get unknown property 'testSourceDirs' for object of type org.gradle.plugins.ide.idea.model.IdeaModule

when i run the app i got error of
Could not get unknown property 'testSourceDirs' for object of type org.gradle.plugins.ide.idea.model.IdeaModule.
I got same error. I had to delete JUnit dependencies from 'build.gradle' file.I also removed test .java and .class files along-with their directories. After syncing the gradle, the error was gone. You can try these steps after backing up files. After that, you can try reintroducing updated dependencies and test files. Hope it helps.

Why is Android Studio trying to concatenate filenames during the build process?

I'm trying to build this project: https://github.com/sureshjoshi/android-ndk-swig-example
It's a small example project that uses SWIG to wrap a C++ library for use on Android. I'm getting this error when it builds:
C:\Users\elarson\Desktop\Downloads\android-ndk-swig-example-master\NDKExample\app\src\main\jni\SeePlusPlus_wrap.cxx:802:1: fatal error: opening dependency file C:\Users\elarson\Desktop\Downloads\android-ndk-swig-example-master\NDKExample\app\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/SeePlusPlus/C_\Users\elarson\Desktop\Downloads\android-ndk-swig-example-master\NDKExample\app\src\main\jni\SeePlusPlus_wrap.o.d: No such file or directory
Breaking that up, I see that it's trying to open this file:
C:\Users\elarson\Desktop\Downloads\android-ndk-swig-example-master\NDKExample\app\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/SeePlusPlus/C_\Users\elarson\Desktop\Downloads\android-ndk-swig-example-master\NDKExample\app\src\main\jni\SeePlusPlus_wrap.o.d
Breaking that down further, I see that this filepath contains the absolute path to the project twice, but with the colon replaced with an underscore:
C:\Users\elarson\Desktop\Downloads\android-ndk-swig-example-master\NDKExample\app\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/SeePlusPlus/
C_\Users\elarson\Desktop\Downloads\android-ndk-swig-example-master\NDKExample\app\src\main\jni\SeePlusPlus_wrap.o.d
I'm wondering what might cause this. I have the NDK in a path with no spaces, as that's been known to cause problems. You can see my project has no spaces in its path, either.
The actual line executed during the build that's failing is this, broken up for clarity:
C:\Dev\Android\android-ndk-r10d\ndk-build.cmd
NDK_PROJECT_PATH=null
APP_BUILD_SCRIPT=C:\Users\elarson\Desktop\Downloads\android-ndk-swig-example-master\NDKExample\app\build\intermediates\ndk\debug\Android.mk
APP_PLATFORM=android-21
NDK_OUT=C:\Users\elarson\Desktop\Downloads\android-ndk-swig-example-master\NDKExample\app\build\intermediates\ndk\debug\obj
NDK_LIBS_OUT=C:\Users\elarson\Desktop\Downloads\android-ndk-swig-example-master\NDKExample\app\build\intermediates\ndk\debug\lib
APP_STL=gnustl_shared
APP_ABI=all
This seems to have to do with filepath length. Also had it not work in D:\production\Pong\Devel2010\Src\UnityGames\BhvrDemo\BHVRSWIGTest\
I moved my project folder from
C:\Users\elarson\Desktop\Downloads\android-ndk-swig-example-master
to
D:\Almo\Work\android-ndk-swig-example-master
And now it works, but perhaps only because the filenames are shorter:
D:\Almo\BinkSWIGTest2\NDKExample\app\build\intermediates\ndk\debug\obj\local\arm64-v8a\objs\SeePlusPlus\D_\Almo\BinkSWIGTest2\NDKExample\app\src\main\jni\SeePlusPlus_wrap.o.d
is still created.

Error while adding mp4parser library to a project in android studio

I'm trying to use mp4parser library in my project. My android studio version is 1.0.2. Here's what I've done so far:
I've downloaded mp4parser zipfile from the link: https://github.com/sannies/mp4parser
I've extracted the zip file to MyProjectName/app/libraries
Renamed the folder to mp4parser
Add this line of code to settings.gradle file:
include ':app:libraries:mp4parser'
Add this line of code to build.gradle (in dependencies block):
compile project('libraries:mp4parser')
Now I want to sync the project with gradle files. This error pops up:
Error:Configuration with name 'default' not found.
I don't have this problem with other libraries. Seems that its only mp4parser that I have problem with. How can I fix this?
If you're including the library as source, the best thing to do is to unpack it somewhere and import it as a module.
The error you're getting is cryptic but it means that the build system is looking for a build.gradle file at that location and not finding it (or it doesn't see an apply plugin statement in the file telling it what to do). I'm assuming that the library you're trying to use doesn't have a Gradle build script.
If you import the library using the Android Studio UI, a build script will be generated for the module and you should be good to go.

Unable to execute dex: Multiple dex files define Lcom/actionbarsherlock/R$attr;

i use ActionBarLibrary in a library, that I use in a my app
i got this message when i try to compil
[2013-01-28 16:09:46 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/actionbarsherlock/R$attr;
[2013-01-28 16:09:46 - comfree] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/actionbarsherlock/R$attr;
As asked here, I was facing the exact same error yesterday. I pinpointed the cause of the error to /bin/classes. If I deleted the /classes dir before running the app, the app would compile and run. Of course, when I tried to actually export the app, the /classes dir would come back and along with it the error.
The solution to my problem was to install the latest version of Eclipse. You will then need to install the latest version of the ADT but all the Android versions you have downloaded earlier for the other Eclipse installation will be detected and used for this one as well. When I export or run the app through Eclipse, the /classes folder does not appear now.
right click on project to go project property>>java Build path>>choose Order and Export and then Unselect all except android4.0 or what every you have then clean and build your project ,now error not come again..
The solution to my problem was that I deleted the jar files which I copy pasted in project's lib folder. I explicitly imported external jars in build path

Android NDK java.lang.UnsatisfiedLinkError: findLibrary returned null

Having the above error in your Android JNI app? Read on...
Up front, I'll say that I've already solved this, in my own way, but I feel something in the Android build system (perhaps regarding Eclipse) is broke, and I hope to save someone else hours of pain. Perhaps others have come across this issue and can comment on what worked for them.
For a while, I've had an Android project with some JNI code that I developed using the NDK. Then, today, I changed something in the java code and then poof, I could no longer load my JNI library. It failed with an exception like:
E/AndroidRuntime( 999): java.lang.UnsatisfiedLinkError: Couldn't load mylibrary: findLibrary returned null
I googled and tried everything (rebuilding, close and relaunch Eclipse, etc, etc)
What finally fixed my problem? I physically uninstalled my app from the device before trying another run. That's it. After that, it worked. What worked for you?
If you have a native project with LOCAL_MODULE "libXYZ", make sure to load it as
System.loadLibrary("XYZ");
If you are trying to run your app in a simulator, then make sure that you have specified the correct architecture in Run -> Run Configurations -> Target (you may need to add the required simulator using Window -> Android Virtual Device Manager).
I had the same problem when trying to execute an app in an Intel simulator, while the app was using a library precompiled for the ARM.
I've got this issue too, but for my situation, i'm using my libs in another project. And I don't think it's a matter of eclipse or android-ndk.
you may check these tips that can lead to UnsatisfiedLinkError and it works fine for me, good luck :)
must following the JNI interface's nameing rule(you said that you did load the library successfully before, so you can ignore this) and the libraries must in directory /your project/libs/armeabi/
if you ensure the above things are done, then you must ensure that your generated libs are installed into your app.apk, otherwise it will still cannot find the lib and thorw you an error. to do this, you right click on your eclipse project name, and go into Build Path - Configure Build Path, on the left menu, choose Java Build Path, then click on the Order and Export tab on the right panel, checking the checkbox before your library name and click OK, then clean,rebuild and run you project, and your libs will be installed into app.apk, things are done.
EDIT:
in a word, UnsatisfiedLinkError are thrown if the library is not installed into your app.apk, so it cannot be linked sucessfully.
In my case, while making a System Application the issue was related to permissions. After putting the ".so" files into /system/lib/ or /system/vendor/lib/ directory, I modified the default allocated permissions 600 to 755. It worked well.
Inside libs folder, I create a new folder called armeabi-v7a, and copied the .so file from armeabi to the new folder. It solves the error.
I was having the same issue and these are some of the problems I had with my project:
Changing from System.load("hello-test"); into System.loadLibrary("hello-test");;
Changing the C function signature to JNIEXPORT jstring Java_com_example_testndk_TestNDK_funcNami(JNIEnv* env, jobject thiz): here you use Java_<java_package_name>_<java-class-name>_<function-name>;
Adding NDK path to local.properties, in my case ndk.dir=<my-path-to-ndk-directory>; and
Updating my build.gradle to also include within defaultConfig: ndk { moduleName "hello-test" }.
Package name: com.example.testndk
Java class name: TestNDK
C source name: hello-test.c
JNI directory location within the project structure: AndroidProjects/TestNDK/app/src/main/jni
IDE: Android Studio 0.8.1.
First, check you have the jni files inside you libs folder in eclipse or jniLibs folder in android studio. When you checkin in any svn, cross check to check in the .so files too.
My Scenario was when Building with Android studio.
When you are building in android studio, your library .so files or (jni) files should be inside the \src\main\jniLibs\armeabi***.so folder.
where as these files will be inside the \libs\armeabi***.so in eclipse.
When building using both eclipse and android studio, you have to modify your build.gradle file as
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
// Fixed Issue : "android studio java.lang.unsatisfiedlinkerror: couldn't load find library returned null"
// Cause : For android studio : The JNI files should be placed in the /src/main/jniLibs folder.
// Fix : Mapping the jniLibs 's source Directories with Lib's folder
jniLibs.srcDirs = ['libs']
}
Here I am building the project using both the android studio and the eclipse.
just had a similar problem.
Check out your /data/data/your.package.name/lib directory
When i ls in my package directory it currently displays:
lib -> /mismatched_uid/settings_10037/fs_1000
probably i accidently switched the sharedUserId and thus the library can't be accessed anymore.
None of the previous answers solved my problem, but this did: All along the problem was that a necessary subdirectory and file were not present. All I had in my libs folder was an armeabi folder containing the proper .so file, but there are supposed to be 3 others, each with a .so file in them. Not certain yet which of the other three (armeabi-v7a, mips, or x86) was the required one, but I do know that all three were automatically generated when I added the Application.mk file to the same folder as the Android.mk file, and made sure it had the following line in it:
APP_ABI := all
For me, that line is the only text in there. When ndk-build is then run the Application.mk file apparently causes "all" the 4 folders to be created and the proper .so files to be created in them. Once I got Application.mk in place, I ran ndk-build again, and then did a clean and a clear on my Eclipse project before trying again. Everything ran perfectly.
No need to root the device..deploy app on emulator and browse the folder
If you have a native project with "libXYZ.so", make sure that /system/lib/libXYZ.so does not exist on your device. There is a painful workaround: use
System.load("/data/data/your.package.name/lib/libXY.so")
instead of System.loadLibrary().
I just had this happen and the problem was that the device simply did not have enough space to install the library. I uninstalled some other apps and then it worked.
Had identical problem.
Just cleaned project and it worked. Mystery..
UnsatisfiedLinkerror is solved by this.Build your .so file again by "ndk_build"
I added
extern "C"
before functions declare
ex:
extern "C"
jstring
Java_lara_myapplication_MainActivity_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
}
then the error was gone
Add this following code inside your gradle file
//libs is the location of your library's folder, It varies in diffarent projects like src/main/libs etc.
android {
sourceSets.main {
jniLibs.srcDir 'libs'
}
}
So, Android Studio keep on looking native libs inside jniLibs folder. this code will change the path of android studio to look libs in libs folder
In my case .so library is loaded correctly, but can not find method like below:
Caused by: java.lang.UnsatisfiedLinkError: Native method not found...
After hours of searching what can be problem noticed that application throws related error only for production flavor. Yes, we use proguard to obfuscate source code and it breaks .so library handler class... After adding below lines into proguard rules file. It started working as expected.
-keepclasseswithmembers,allowshrinking,allowoptimization class com.zk.android.jni.Device {
native <methods>; }
So if you use proguard and having similar problem with mine. Please check proguard file...

Resources