Error message:
Actually,my environment is good when my disk not broken. However,when I change a new disk, download new ndk package, then set my NDK_ROOT, and ANDROID_NDK, like this:
Env variables:
my ndk-build is not working. Is something wrong in my environment?
Here is an example for Android JNI: https://github.com/russell-shizhen/JniExample, you should start from some tutorial project first.
Related
How can I build an APK file from the command line? I've tried
MSBuild myProject.dproj /p:Config=Release /p:Platform=Android
but no APK file is produced, only the .so file.
Some experimentation shows that the following aspects of the various proposed courses of action come into play for a more complete picture.
When you create a new Delphi multi-target project (let's call it Foo) you have one MSBuild-compatible file created: the Foo.dproj Delphi project file. In the case of Android (the platform in this question) this is enough to build the target libFoo.so library file that would eventually become part of a deployed .apk file, but is not enough to make the .apk file just yet.
You can build your .so file, which contains the ARM machine code, using a command line like this:
msbuild Foo.dproj /property:Config=Debug /property:Platform=Android /target:Build
or this more concise version:
msbuild Foo.dproj /p:Config=Debug /p:Platform=Android /t:Build
As per the documentation you can use the Deployment Manager's Deploy button to create an additional MSBuild file, or indeed just choose the Project, Deploy libFoo.so menu item. The initial step of this deployment is to create a Foo.deployproj file, which is another MSBuild-compatible file.
With Foo.deployproj file present this following line will take the libFoo.so file and anything else required for deployment and use these to build up the .apk Android application package file:
msbuild Foo.dproj /p:Config=Debug /p:Platform=Android /t:Deploy
The Deploy target will fail if the required files such as libFoo.so are not present, say by previously running MSBuild using the Build or Make MSBuild targets: s(431,5): error : Required local file "Android\Debug\libFoo.so" not found. Deployment failed.
Additionally the Deploy target fails if you have not got a Foo.deployproj file generated for your project: error MSB4057: The target "Deploy" does not exist in the project.
That said, if you have the Foo.deployproj present you can build and deploy in one fell swoop with something like:
msbuild Foo.dproj /p:Config=Debug /p:Platform=Android /t:Build;Deploy
Of course to avoid compiling files that have not changed this is perhaps better:
msbuild Foo.dproj /p:Config=Debug /p:Platform=Android /t:Make;Deploy
The fact that the documentation doesn't mention anything about the Deploy target is a little confusing. There is potential to think that it implies you run MSBuild against Foo.deployproj file, but that yields no joy whatsoever. It seems the documentation is out of date or plain wrong.
I found:
MSBuild Project1.dproj /p:Config=Debug /p:Platform=Android /t:Deploy
There is a project on github --> https://github.com/CyanogenMod/android_external_openvpn/tree/ics, after download the sourcecode, I just want to build it use NDK-BUILD command in Linux(Centos 6.3), but the author does not say anything about it;
So, I just ndk-build it (I have test ndk-build is ok), it shows:
Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
What may cause this warning? And how can I build it, thx!
This usually happens when you invoke ndk-build from incorrect diretory. You must be in folder which contains jni subdirectory.
Or alternatively do what error message tells you - specify NDK_PROJECT_PATH to correct folder.
NDK_PROJECT_PATH=/home/cenuser/android/sphinx/PocketSphinxDemo
export=NDK_PROJECT_PATH
I followed this tutorial on raywenderlich.com and I came into a stop on the part where I need to build the native C++ libraries for Android Development.
I am using Mac OS,Cocos2d-x v2.0.1 (latest version), have my Android SDK and NDK set up, and my Eclipse (Helios) with the correct plug-ins needed for C/C++. Now I'm have trouble building the Cocos2d-x libraries for Android development. I'm using the build-native.sh tool. If I use it on the terminal like so:
xxxxx-xxxxx-imac:proj.android xxxxx$ ./build-native.sh
I get the following:
Using prebuilt externals
Android NDK: WARNING: Ignoring unknown import directory: /Users/xxxxx/Desktop/LANCE/COCOS2DX/cocos2d-2.0-rc2-x-2.0.1/cocos2dx/platform/third_party/android/prebuilt
Android NDK: /Users/xxxxx/Desktop/LANCE/COCOS2DX/cocos2d-2.0-rc2-x-2.0.1/CocosDenshion/android/Android.mk: Cannot find module with tag 'cocos2dx' in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?
Android NDK: The following directories were searched:
Android NDK:
make: Entering directory `/Users/xxxxx/Desktop/LANCE/COCOS2DX/cocos2d-2.0-rc2-x-2.0.1/testproj2/proj.android'
jni/Android.mk:19: *** Android NDK: Aborting. . Stop.
make: Leaving directory `/Users/xxxxx/Desktop/LANCE/COCOS2DX/cocos2d-2.0-rc2-x-2.0.1/testproj2/proj.android'
I looked at /Users/xxxxx/Desktop/LANCE/COCOS2DX/cocos2d-2.0-rc2-x-2.0.1/cocos2dx/platform/third_party/android/prebuilt but this directory does not exist (the platform folder is missing from the cocos2dx folder)
How do I fix this?
Thanks in advance.
EDIT: After looking through the scripts, I noticed that the cocos2dx folder in the cocos2dx root folder does not have an Android.mk file.
A re-unpacking of the Cocos2d-x ZIP did the trick. Turns out the files needed were deleted (for some reason) in the Cocos2d-x root folder.
build_native tool is obsolete now, Cocos2d-Console is used instead.
I am getting error while trying to build android ndk project:
error: jni.h: No such file or directory
But: locate jni.h command show me:
locate jni.h
/usr/lib/jvm/java-6-openjdk-i386/include/jni.h
What is wrong in my actions?
EDIT:
If I hardcode it in the source code it work but I have a lot of files that are using this header. What I need to do that all my files can see /usr/lib/jvm/java-6-openjdk-i386/include/jni.h
?
Try setting the installation location of your NDK in PATH in your rc file, let's say ~/.bashrc:
NDK=/path/to/your/ndk/location
export PATH=$PATH:$NDK
Source the rc file by running source ~/.bashrc.
Now when you run ndk-build, it will setup the whole build environment for you by running make command against a bunch of make files under $NDK/build/core, it will setup correct header file search path for your project depending on the android:targetSdkVersion setting in AndroidManifest.xml.
The jni.h needed by your NDK project is located under $NDK/platforms/android-14/arch-arm/usr/include.
Android NDK projects will not use any JNI header files under your JDK installation, files under /usr/lib/jvm/.... will never be touched.
I'm porting a modem connection manager written in C++ from linux to gingerbread. This does not end up being an "app" with a "gui" that I would use a java wrapper with the NDK but a service that is called at boot from "init.rc". I found some not up to date docs related to android build system under build/core/. There you find some html files explaining the basics of Android build system and several "file.mk" which are some templates for common situation like creating a c++ executable, static libraries, shared library etc.
I place my tree with all the sources under external/myservice and it's meant to be compiled at the same time as Android itself. (I've already ported the kernel to my platform and it works, just the modem left to go)
In a subfolder in an Android.mk file, I have a bunch of ".cpp" files listed with the variable LOCAL_SRC_FILES := cppfile1.cpp cppfile2.cpp .... That will generate cppfile1.o cppfile2.o ...
I need to link those cppfile*.o with objfile.o to form a libfile.so. I found the rules on how to generate a libfile.so from a bunch of files.o.
Where things get complicated, is to port the "linux makefile" command to create objfile.o. Here is how it looks like
$(LD) $(LDFLAGS) -r -b binary -o QMIDB.o \
QMI/Entity.txt \
QMI/EnumEntry.txt \
QMI/Enum.txt \
QMI/Field.txt \
QMI/Struct.txt
Which means it is a linker job to merge a bunch of text file to make that objfile.o. That file is just a bunch of initialized data structure, there is no code to execute in it but it's pretty ugly to look at all files.txt with a text editor.
I have no clue how to integrate that in the Android.mk file. How can it be done? I'd even appreciate just a hint on where I can find more information. It is easy to find information on building Android applications but it's another story to find anything closer to Android/Kernel itself.
From the mk. file file you can easily get so file....
You need to use android Ndk setup and cygwin setup if you are using windows platform to genreate so file from your native code.
Firstly install and place ndk to a location...
Then install cygwin setup not default one check all features in the installation process (it a sort of linux terminal) as ndk-build command is recognized from linux terminal.
Now from your cygwin terminal get access to your project folder jni file.. or where mk is placed...
http://developer.android.com/sdk/ndk/index.html
Use the following referal how to run ndk-build command from cygwin terminal..
Now providing complete path of ndk we use the ndk-build command...
After that the complied code generates the .so file for our project...
Now what we are using System.loadlibrary command to use the so file i.e our native code can now be used.
Note to get so file form mk we need to complie using ndk setup.We can't directly copy paste so file to make our native code run.Also we we are using windows platfrom we will need to use cygwin setup to do that