I am using Ubuntu14.04, Eclipse Luna.
I am referring Hello World Example given link
http://www.ntu.edu.sg/home/ehchua/programming/android/Android_NDK.html
My project name is HelloNDK.
My project path is /home/androiddev/workspace_luna/HelloNDK
In AndroidManifest.xml
I can see package which I use is named as: com.delta.hellondk
Android.jar which automatically added in project which is under Android 5.0.1 & its location shown as
/home/androiddev/Applications/Android_sdk/sdk/platforms/android-21/android.jar
When I use javah command, I got error.
I use following line in terminal.
javah -jni -classpath /home/androiddev/workspace_luna/HelloNDK/bin/classes/;/home/androiddev/Applications/Android_sdk/sdk/platforms/android-21/android.jar -o HelloJNI.h com.delta.hellondk
&
javah -jni -classpath /home/androiddev/workspace_luna/HelloNDK/bin/classes/JNIActivity.class;/home/androiddev/Applications/Android_sdk/sdk/platforms/android-21/android.jar -o HelloJNI.h com.delta.hellondk
when I use following command, I got error as follows:
Error: No classes were specified on the command line. Try -help.
bash: /home/androiddev/Applications/Android_sdk/sdk/platforms/android-21/android.jar: cannot execute binary file: Exec format error
Now I search lots of keywords in google, stackoverflow regarding how to generate HelloJNI.h automatically.
But i failed.
Please guide me!
I know its repeate question should be get negative vote, should be 'On Hold'. But then also i doesn’t get any clue so i asked without hesitate.
Related
description
We have a C/C++ project wallet-core that is using third party library libsecp256k1, and we install libsecp256k1 into /usr/local/lib and /usr/local/include, all works well in wallet-core Unit Test, till we add it to android, which call wallet-core.
call links:
android project -> wallet-core -> trezor_crypto -> libsecp256k1
When we run tools/android-test, got error in link period:
xxxx -L/usr/local/lib trezor-crypto/libTrezorCrypto.a libprotobuf.a -llog /usr/local/lib/libsecp256k1.a -latomic -lm && :
/Users/bibodeng/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: /usr/local/lib/libsecp256k1.a: no archive symbol table (run ranlib)
../../../../../../trezor-crypto/src/ecdsa.c:1211: error: undefined reference to 'secp256k1_context_create'
../../../../../../trezor-crypto/src/ecdsa.c:1213: error: undefined reference to 'secp256k1_schnorr_sign'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Configuring for JNI
two function is undefined and there is no symbols, tell me ranlib. ranlib result:
$ranlib libsecp256k1.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive member: libsecp256k1.a(/0) size too large (archive member extends past the end of the file)
I run nm -g libsecp256k1.a also said it's truncated or malformed archive.
Please help me to solve this problem, we have stuck several days. Thanks a lot.
guess reason
I read many answer and guess it's reason:
linker will run ranlib before link, but it fail cause there is no
symbol ranlib failed because libsecp256k1.a
archive file is too big or maybe not in good format
libsecp256k1.a file is not
generated well or ranlib has problems.
codes & config
libsecp256k1: https://github.com/Bitcoin-ABC/secp256k1
./autogen.sh
mkdir build
cd build
../configure --enable-module-schnorr
make
make check
sudo make install
wallet-core: https://github.com/IFWallet/wallet-core/tree/free_cash
git clone git#github.com:IFWallet/wallet-core.git
git checkout free_cash
cd wallet-core
./bootstrap.sh
./tools/android-test
download the codes from github and checkout free_cash branch, run upper cmd will get the same error.
relate answers
I already try this answer, but not work.
ndk-no-archive-symbol-table
I wanna use tesseract library with my application so i need to implement ndk.i download it add its path to my bash_profile.
export ANDROID_ADB=/Users/gokhanaliccii/Library/Android/sdk/platform-tools
export ANDROID_NDK=/android_ndk/android-ndk-r10d
export PATH=$PATH:$ANDROID_ADB:$ANDROID_NDK
My problem is appeared when i run -javah command at studio terminal. My command is
javah -d jni -classpath /Users/gokhanaliccii/Library/Android/sdk/platforms/android-19/android.jar:/Users/gokhanaliccii/Documents/gokhan_private/android_ocr/NDK_TEST/app/build/intermediates/classes/debug gokhanaliccii.kou.ndk_test.MainActivity
after i got this error i tried to add support libraries
I tried to solved it but i coulndt find solution i'm really exhausted i hope someone know how to solve it
My project is at /Users/gokhanaliccii/Documents/gokhan_private/android_ocr/NDK_TEST
Dont need cp for javah
Run javac on source that includes file with native headers.
Cd to path that is parent of the root of where the ".class" files are.
On cli or in terminal run the javah ( no cp needed )
If stuvk do the ndk samples and it will make sense . They walk u thru javah sample
After lot of researches and training i solved my problem.
javah -classpath /Users/gokhanaliccii/Library/Android/sdk/platforms/android-19/android.jar:/Users/gokhanaliccii/Library/Android/sdk/extras/android/support/v7/appcompat/libs/android-support-v4.jar:/Users/gokhanaliccii/Library/Android/sdk/extras/android/support/v7/appcompat/libs/android-support-v7-appcompat.jar:../../build/intermediates/classes/debug -d jni gokhanaliccii.kou.ndk_test.MainActivit
My result command is above.I tried it at android studio,classes files are at build/intermediadtes/classes/debug if you want try it at eclipse it is under bin folder.
I'm trying to create a .h header file for a simple NDK project. Using cygwin I browse to myprojectDIR\jni directory, then execute this command:
javah -o com_myproject_MyActivity.h -classpath myprojectDIR\bin\classes com.myproject.MyActivity
then this error message appears:
Error: cannot access android.app.Activity
class file for android.app.Activity not found
I have a native method inside MyActivity class, so I tried to create a new class called NativeAccess (does not extend any class from the android SDK) and it worked fine, the .h file was created, ndk-build and test on device where successful!
So my problem is that I need my native methods inside android activities and services that I create, but I cant do that because the Javah command cannot access classes from inside the android-sdk itself. Please notice that I'm using (Windows-7 x64) and I have these environment variables:
ANDROID_NDK : C:\Android\android-ndk-r7b
ANDROID_SDK : C:\Android\android-sdk
ANT_HOME : C:\ANT\apache-ant-1.8.3
JAVA_HOME : C:\Program Files\Java\jdk1.7.0_02
PATH : %JAVA_HOME%\bin;%ANDROID_SDK%\tools;%ANDROID_SDK%\platform-tools;%ANDROID_NDK%;%ANT_HOME%\bin; (other unrelated stuff)
Thanks in advance
Try adding to your classpath:
-classpath <android-sdk-location>/platforms/android-8.jar
I found it, this is how it goes:
javah -o com_myproject_MyActivity.h -classpath <android-sdk-location>/platforms/android-8.jar;myprojectDIR\bin\classes com.myproject.MyActivity
Try the following in Eclipse,
Go to > Run | External Tools| External Tool Configurations
Under Program create new configuration by clicking small icon.
Name it.
Location would be : C:\Program Files\Java\jdk1.7.0_04\bin\javah.exe
Working Directory would be: ${workspace_loc:/My_First_NDK/bin/classes} and
Arguments would be: -classpath ${workspace_loc:/My_First_NDK/bin/classes} -bootclasspath "C:\adt-bundle-windows-x86-20140624\sdk\platforms\android-19\android.jar" -v -d ${workspace_loc:/My_First_NDK/jni} com.mypackage.ndk.HelloNDK
In order to generate native header files javah needs:
your classes (usually under build/intermediates/classes)
Android classes (usually under $ANDROID_HOME/platforms/android-%ver%/android.jar)
So you simply pass them in -classpath argument
The main challenge for me was basically passing both of them - you have to use : as a separator and paths must be absolute.
See Oracle docs
Thus you may end up with something like this: javah -classpath <full path to app>build/intermediates/classes/debug:<full path to sdk>/platforms/android-26/android.jar com.myproject.MyActivity
I found it, this is how it goes:
E:\workspeaceResearch\DAMMADARJNI\src>javah -classpath "E:\Software\sdk\platform
s\android-19/platforms/android-8.jar"; -jni com.dammadar.jni.Home_Screen
I have a kind of strange issue. In my bash script or Makefile, using aapt with absolute path does not work but if I am in the local directory it does.
If I do the following, it does not work:
aapt add $OUT/device.jar $OUT/classes.dex
The command does run and print this output:
'/homes/rsevile/CS307/bin/Device/classes.dex'...
But when trying to load the jar, the class that I am trying to load end up being not found.
The following does work though:
cd $OUT
aapt add device.jar classes.dex
Printing:
'classes.dex'...
This is the whole code being executed in the script (which works):
javac -d $(OUT)/classes -classpath ./layoutlib.jar src/com/device/client/*.java
jar cf $(OUT)/device.jar $(OUT)/classes $(OUT)/layoutlib
dx --dex --no-strict --output=$OUT/classes.dex $OUT/device.jar
cd $OUT
aapt add device.jar classes.dex
cd $ROOT
adb push $OUT/device.jar $ANDROID_OUT_DIR
I am confused why my class ends up being not found when using an absolute path with aapt.
Could anyone please explain to me why it is not working and how I could fix it to use a proper absolute path please?
Thank you.
I realized that aapt actually keeps the absolute path, there is no way around it.
I fixed the problem by reusing jar and using the -C option that lets me specify a directory.
I think I'm doing the classpath wrong on the command line, and I get the following error:
My android program uses Bitmap from the package android.graphics.Bitmap
thomas#THOMASDESKLINUX:~$ javah -verbose -classpath :/home/thomas/Documents/LinuxProgramming/AndroidSDKs/android-sdk-linux_x86/platforms/android-8.jar;/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/bin org.me.renderscene.Billboard
Error: No classes were specified on the command line. Try -help.
bash: /home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/bin: is a directory
and javah cant find the class
thanks!
The problem with your command is that you are using the Windows Path Separator ; on the command line, rather than the Linux Path Separator :. I also recommend to add the current directory to javah: ., the correct command to generate header in your case is:
javah .:/home/thomas/Documents/LinuxProgramming/AndroidSDKs/android-sdk-linux_x86/platforms/android-8.jar:/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/bin org.me.renderscene.Billboard
Tip: javah doesn't need all dependency libraries to generate the headers, it will output warnings but thats OK. So using this tip, we can generate the headers with:
javah .:/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/bin org.me.renderscene.Billboard