I try to import example projects using Android NDK 7 into Eclipse.
The problem is that no matter how I do it. The project always ends up being completely empty.
For example I tried to import the hello-jni example.
I have both tried to import it via:
New -> Project -> Android Project -> Create project from existing source
Import -> Existing Projects into Workspace
Both times the computer seems to find the AndroidManifest.xml as it correctly fills out the fields for package name, etc. But as soon as I press Finish I only have an empty project.
The same procedure works for Android Projects not using the NDK as e.g. the Snake example from Android SDK. The behaviour is also consistent between MacOSX Lion and Windows.
What do I need to import the existing Android NDK examples into Eclipse.
NOTE: I managed to import the projects, when I copy the ndk into the root directory. However in the NDK documentation it says I can put in into any directory I want and I would rather not have it in the root directory. Any ideas why it only works there?
You can compile in eclipse though, In Short :-
This assumes you can compile from command line, i.e. you have ndk-build on your path so you can call ndk-build from command line.
This works on in Helios Version: Helios Service Release 2.
Download the CDT plugin for Eclipse for starters, i presume you know how to get plugins into Eclipse. its under LANGUAGES , install all non incubation plugins for C/C++.
Create your Android Java project (or import the example project), add your JNI folder and also your Android.mk in this directory.
Go FILE / NEW / OTHER
Then if CDT is installed correctly Under C/C++ / ( Convert to a C/C++ Project )
Check the project, choose MakeFile Project and Other Toolchain click NEXT
Next go PROJECT / PROPERTIES / C/C++ uncheck " use default build command" replace "make" with "ndk-build"
This works for me :)
Probably you don't have .so file. Use cygwin and ndk-build to create it. In jni folder you have .mk file
Related
I used PhoneGap 2.* without any problems, but now I cannot, for the life of me, get a basic “hello world” to work. I want to use the “platform-centered workflow” because my 2.* projects have a lot of customization.
Here’s what I’m doing:
I’nm on a Mac and have a folder ~/desktop/android with all my Eclipse projects.
Download https://www.apache.org/dist/cordova/platforms/cordova-android-3.5.0.zip
Unzip it and put it in ~/desktop/android/cordova-android
Run /users/me/desktop/android/cordova-android/bin/create /users/me/desktop/android/hello com.example.hello HelloWorld
The project is successfully created!!!
As per the PhoneGap docs, I go to File > New Project > Android Project from Existing Code and select the “hello” directory.
I also check “copy projects into workspace” because it doesn’t work if unchecked.
There are actually two projects HelloWorld and HelloWorld-CordovaLib. I check them both.
If I try to run HelloWorld as an Android application, I get the following errors:
Config cannot be resolved
CordovaActivity cannot be resolved to a type (x3)
The import org.apache.cordova cannot be resolved
The method on Create(Bundle) of type HelloWorld must override or implement a supertype method
After looking over some previous questions, I decide to import cordova-android using File > Import > Existing Project into Workspace
Right click on the new Cordova folder in Eclipse and under Android make sure is Library is checked.
I clean and build everything.
I now get the error “the project cannot be built until path errors are resolved”
What do I need to do to get a basic hello world PhoneGap 3.5 working???
I figured out that the problem was creating the project in the default Eclipse project directory. I created the project in a new directory:
/users/me/desktop/android/cordova-android/bin/create /users/me/desktop/mynewfolder/hello com.example.hello HelloWorld
Then in Eclipse, I did File > New Project > Android Project from Existing Code, check both projects but did NOT check copy projects into workspace.
Now I see that the HelloWorld-CordovaLib is green checked under libraries. After a few cleans and builds it all works.
As mentat said, I did not need to import the conrova-android project.
You don't have to import cordova-android. Make sure you have a reference to HelloWorld-CordovaLib by right click on HelloWorld project, Properties -> Android - Library list -> Add
It should have a green check for CordovaLib. Also try project -> clean the project, Eclipse needs it often.
Background
I've made a tiny SDK for bitmap handling using JNI (link here).
It has only 2 projects : a sample project (demonstrates usage of the SDK), and the SDK itself .
The SDK project is an Android project, and it includes some C/C++ code within it.
The problem
For some reason, even though when I've created the project , everything went fine, now that I try to get the library project and import it to Eclipse, and then I open the CPP file I've made, I see plenty of errors on it, as such:
The question
Why does it occur? How do I import the project correctly? Can I help whoever is using this to be able to import it nicely?
I've tried to create a totally new project with JNI and just copied (carefully) the files from my library, and it compiled fine, but that's not a nice way to import a project...
This eclipse error happens often , and your solution (starting a empty project then adding the files) is the fastest work-around, and we all use it when it comes to this.
Another solution would be to remove the c nature and Android nature and add again these natures to the project (often times this works as well).
When a new project is created, Eclipse will add it's natures and it's tool chains. If you import an old project, these toolchains / natures might be badly imported.
For a project containing c and c++ , you will need to have cnature and ccnature defined in your ".project" file. For android you need Android Nature.
For compiling android, you will need to have com.android.gcc as the toolchain defined in your .cproject file.
Depending on the version of ADT / CDT / Eclipse , the value from the toolchains in .cproject differs, hence they aren't easy to import from machine to machine.
My guess is you have your storm of errors because the .cproject file was generated wrongfully .
EDIT
After Android Developer's further research, a faster way to bypass Eclipse's limitation caused by how native nature is added to a project can be done in the following steps:
delete from the ".project" file the "cnature" and "ccnature"
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
delete the ".cproject" file from eclipse workspace
remove all generated files and folders : libs, obj, gen and bin
Re-add the native support for android via the "android tools" context menu
Thank you android developer.
Cordova 3.3.0 installed from fresh and PATH fixed with visibility to tools etc.
Build a new bare application
Add android platform
now it starts to go awry -
Following instructions to import to Android Development Tools ( Eclipse ) I get TWO projects created
HelloWorld and HelloWorld-CordovaLib
HelloWorld has errors as it can't see/does not have the the cordova.jar file ( assuming this from past experience )
HelloWorld-CordovaLibs is whats missing from the HelloWorld project all the source to Cordova
Assuming that I need the jar file I dig around and try running ant jar from within the android part of my project
Running ant jar fails -
Target "jar" does no exist in the project "HelloWorld"
which is an ant error telling me it doesn't know how to build target jar.
look at build.xml in the android directory confirms this - no section on "jar"
A bit more digging on the net and the Apache Cordova git repository seems to intimate that I should have another file build.xml inside a directory 'framework' with the jar target defined.
Ahhhhh - no framework directory anywhere.
Can anyone work out where this is all going wrong before I tear any more hair out?
I followed this guide to create a Cordova 3.3.0 project, import it into Eclipse, and successfully run it on a device from Eclispe: http://cordova.apache.org/docs/en/3.3.0/guide_platforms_android_index.md.html#Android%20Platform%20Guide
You are right that it imports "HelloWorld" and "HelloWorld-CordovaLibs". This is because of https://issues.apache.org/jira/browse/CB-5232, which makes Android now use the CordovaLib instead of the .jar for a variety of reasons (see the bug report.) You should import both projects into Eclipse (I'll change this in the documentation).
If you follow that guide you should be fine. You don't have to build a .jar anymore.
steps
1- after create the project i import both "hello" and "hello-cordovaLib"
2- i remove the reference to "hello-cordovaLib" from "hello"
3- build the "hello-cordovaLib"
4- restore the reference to "hello-cordovaLib" from "hello"
5- clean "hello" and run
In short .... The ide ( either eclipse or ADT ) needed the initial build of the sub project to allow the HelloWorld project to 'see' the HelloWorld-cordovaLibs project.
What solved my problem on HelloWorld project in my ADT is :
I cleaned both the HelloWorld and the HelloWorld-cordovaLib.
Right clicked on HelloWorld-cordovaLib ->properties->Android and verified
it the isLibrary is checked.
I right clicked on HelloWorld proj -> Properties ->Android -> The "is Library part" had Cordova with red check on it then I clicked on "Add" button and again added Cordova to the project which came with "green check" and then removed the red checked cordova.
Cleaned the projects and now its working fine.
I'm looking to incorporate the NDK for C++ code use in my Android project. I'm using Eclipse Android IDE and I've just downloaded android-ndk-r9-darwin-x86_64.tar.bz2 for OSX 64bit. I've uncompressed the ndk and have it in my home folder, but when I attempt to setup the path inside Eclipse prefs, I get this error
I've looked at this similar question (Eclipse error: invalid path for ndk?) for answers, but every suggestion didn't solve the problem. Other relevant information, I have Make 3.8.1, up-to-date SDK, Sequoyah.
I had the same problem and documented the solution to this problem. It are the first 2 steps of the next link you'll need:
http://aplacetogeek.wordpress.com/android-with-opencl-tutorial/
Edit:
The solution is this:
Step 1: setup Android NDK
Download the NDK from:
http://developer.android.com/tools/sdk/ndk/index.html
I unzipped it in the adt-bundle but you can unzip it anywhere you
want.
Note or remember the path you used. I'll need it in the next steps!
Go to Window -> Preferences -> Android -> NDK
Browse to android-ndk-r9c.
Example: /home/dries/AndroidDev/adt-bundle-linux-x86_64-20131030/android-ndk-r9c
Click apply and ok
Step 2: configure Android NDK for your project
Right click on your project folder. Choose android tools -> add
native support (! the bottom one !) and click finish.
The file you just created is going to be your own .so file. This
will be your personal library with the functions you create yourself
in the JNI folder.
Now you should see a JNI folder in your project with a .cpp and an
Android.mk file in it.
Go to project -> properties -> C/C++ build -> build variables -> add
Name: NDKROOT
Value: your android-ndk-r9c folder you also added to NDK in step 1.
Click Ok
Go to C/C++ build and uncheck Use default build path.
Change the
build path to ${NDKROOT}/ndk-build. Make sure you did not end the NDKROOT value on / !
Click apply
You should be able to use the NDK now and compile without errors.
Found a work-around solution to my question with the help from this forum: https://groups.google.com/forum/#!topic/android-ndk/YPFPa9Fen7Y
I downloaded an old copy of the NDK (r5b) and there were no errors when setting up the path, as opposed to r9 the most recent version. As the forum says, the problem lies with Sequoyah which has not updated since 2011 and can not recognize the new structure of that the NDK is laid out in. Hope this helps someone in the future. (If you find a direct solution though, let me know.)
Instead of downloading another version of the NDK, I simply created links inside the build folder to the toolchains, prebuilt and platforms which recreates the folder hierarchy of the r4 NDK.
Doing this made the plugin happy, and I only have one version of the NDK on my computer.
I've read all of questions forums and blogs about it but i still have a problem. Firstly, i ticked tess-two as a library also my project's using tess-two as a library. I downloaded Android-NDK and from my project's properties i clicked Builders and then new -> Program then i choose ndk's ndk-build file. By the way my project is Gautam Gupta's project. He'd given project. Link: https://github.com/GautamGupta/Simple-Android-OCR. When i run that project in my phone, application starts and captures photo but when i press save then application gives error below. http://t1307.hizliresim.com/1c/l/qg0rl.png
Looks like you need to download only TessTwo, make sure you have properly setup the environments variables (ANT_HOME, ANDROID_HOME and ANDROID_NDK) so these point to where you have Ant and Android SDKs.
Then it's a matter of building the project by following TessTwo guidance. That you set up the library-project that can be imported.
Don't forget that the line commands must be performed in CygWin. Once the library project is built you should have correct .so files in libs/*. In order to actually use these, you could start with this link.
#Burak:
I have solved my problem. For Windows;
Write the codes below to Cygwin
a.cd <project-path'i>/tess-two
b.export TESSERACT_PATH=${PWD}/external/tesseract-3.01
c.export LEPTONICA_PATH=${PWD}/external/leptonica-1.68
d.export LIBJPEG_PATH=${PWD}/external/libjpeg
e./cygdrive/<ndk-directory>/ndk-build
Write the codes below to CMD
f.android update project --target 1 --path .
g. ant release
Don't forget the "." at step f.