Android NDK app won't run - android-ndk

I've been trying to get started on adding native code to my android app so I've looked through a plethora of Android NDK tutorials all to no avail. I can't get any of the apps to run on my emulator or my Galaxy S3. I keep getting the same error: "Unfortunately, [AppName] has stopped working"
My ndk-build command works successfully and I get a .so file. I don't know what the .so file is supposed to look like. Here's mine
http://txt.do/klo0
it looks like gibberish to me but what do I know?
This is my logcat
http://txt.do/klod

In the Android NDK directory, there is a hello-jni example. Try to compile and run it, it works.
It's in the samples/hello-jni directory of your NDK, I have it in ~/android-ndk-r9d/samples/hello-jni. Copy ("import") it into your workspace and compile.
To generate the headers:
cd bin/classes
javah com.my.package.name.MyClassName
Note that the library is usually placed by ndk-build into the libs/something subdirectory of your project, for example, libs/armeabi-v7a, and the file jni/Application.mk specifies what something is, e.g.
APP_ABI := armeabi-v7a
or
APP_ABI := all
The library will be placed in your apk and installed in a subdirectory of your application's data folder.
System.loadLibrary("stuff"); // libstuff.so
will find it. (Note that if you run your app as a system app, that's a different story.)
A library built for a wrong target will not work.

Related

Android NDK: How do I rebuild the .APK file(s)?

I'm building my NDK project on a Mac from the command line (Terminal). I am able to compile and link my "libmain" and I have been using Android Studio to install the built app on my phone.. or at least so I thought..
From what I can see, my .apk file is not changing at all when I run ndk-build.
That would mean that the same broken application is being installed on my phone over and over again even though I'm recompiling my source..
MacbookPro:android-TT admin$ find . -name "*.apk"
./app/build/outputs/apk/app-debug-unaligned.apk
./app/build/outputs/apk/app-debug.apk
The timestamps for the above .apk files never change when I do an ndk-build. I guess Android Studio must be responsible for building these?
Can ndk-build be used to create the .apk file(s) or should I be calling another utility to generate the .apk file(s) ?
I would have thought that Android Studio would have detected change in my libmain output and rebuilt the .apk file(s) but I could be wrong.
cd .. (to folder with AndroidManifest.xml)
android update project --name app --path . --target "android-14"
ant -v debug

Artoolkit source code file cannot execute successfully in Android Studio

I downloaded the Artoolkit SDK in https://github.com/artoolkit/artoolkit5
And there is a directory called AndroidStudioProjects, which can be directly opened by using android studio.
I have configured all the jdk, android sdk, ndk.
However, those projects all have the error like this:
E/art: dlopen("/data/app/org.artoolkit.ar.samples.ARMovie-1/lib/arm/libARMovieNative.so", RTLD_LAZY) failed: dlopen failed: could not load library "libcurl.so" needed by "libARMovieNative.so"; caused by library "libcurl.so" not found
The main problem is could not load library "libcurl.so" needed by "libARMovieNative.so".
Can anyone help me please?
First you have to execute
$NDK/ndk-build
in the directory AndroidStudioProjects/ARMovieProj/aRMovie/src/main/jni/
which creates the libraries for a couple of architectures.
If you have not already done so far you have to execute the build.sh in the android directory of artoolkit.
If you don't want to build for every architecture feel free to modify
android/jni/Application.mk
ARMovieProj/aRMovie/src/main/jni/Application.mk
to for example
APP_ABI := armeabi-v7a
Make sure the arMovie.gradle has got the following inside the android block
android.sources.main.jniLibs {
source {
srcDirs = ['src/main/libs']
}
}

Android NDK: No rule to make target with MuPDF

I am using this link, the answer by star18bit, to integrate MuPDF with my Android project.
I am able to run the ndk-build that is inside the MuPDF's android folder. But when I copied all MuPDF's files to my own project, and ran ndk-build from my project's jni folder, it gives this error:
make: *** No rule to make target ../jni/fitz/base_context.c', needed by ../jni/fitz/base_context.o'. Stop.
Any help to resolve this would be greatly appreciated!
I am following this link as it is, i.e., using the mupdf version 1.2 and android ndk r8e
I was trying to build this on MAC, but gave up.
Finally I did it on Windows 7, encountered a lot of issues while doing it. So I made a tutorial for it, for other users so that they don't have to go through the pain that I went through!
Here's the link:
http://howtojava.net/tutorials/android/integrate-mupdf-with-android-in-windows-7

Unsuccessful ndk build of my 2.6.7 Vuforia project in new Vuforia 3.0 SDK

I tried to run my ImageTargets 2.6.7 version in a new computer which runs new Vuforia SDK 3.0, android ndk 10 and all updated software according to Vuforia's Development Guide that I installed now, but I can't build successfully my C++ libraries, having the following error in Cygwin:
Android NDK: ERROR:jni/Android.mk:QCAR-prebuilt: LOCAL_SRC_FILES points to a missing file
Android NDK: Check that jni/../../../build/lib/armeabi/libVuforia.so exists or that its path is correct
/cygdrive/c/Development/Android/android-ndk-r10c/build/core/prebuilt-library.mk:45: *** Android NDK: Aborting . Stop.
I updated all system paths in Environment variables, I made all alterations according to this link (https://developer.vuforia.com/resources/dev-guide/migrating-your-android-sdk-project) in my project, but the problem still remains.
What can I do please?
Your response is really important for me
Looks like the path of the libVuforia.so file is not correct. To eliminate the doubt - use a full path to the file (not ../../../). That can be configured in your jni/Android.mk file.

Building icsopenvpn

I have some issues in building ics-openvpn project. When I deploy the app on the device and try to import a .ovpn file, I get cannot find minivpn. I think this error is related to an error during the app building.
I've downloaded android NDK and set the path in Eclipse, downloaded cygwin and launched ./build-native.sh, but it returns me the error
./build-native.sh: line 1: ndk-build: command not found
I've tried to modify the path in the .sh with the path of ndk-build, but I get another error:
NON-CYGWIN COMPATIBLE MAKE PROGRAM.....
Anyone knows what steps I have to follow to properly build the project?
You should not try to build it with the cygwin. There is also a build-native.bat in the project which allows the project to be build with windows. Make sure that you have installed the ndk and ndk-build is in your PATH.
Run build-native.bat
make sure you must have NDK 8b and set the environment variable for the ndk file

Resources