Cordova ant jar not available - android

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.

Related

Import Android project not select 'copy project into workspace' error

I have a problem with importing Android project to Eclipse in three scenario:
I have clone my Android project from Bitbucket and synchonized with Eclipse workspace successfully! But the project raise many error.
Then I remove my project and using import function in android (File>import project). I import the project from repo and also check to 'copy project into workspace', awesome! the project work perfectly.
Then I testing again. I also use import function and not check on 'copy project into workspace', oh no, the project keep the error like scenario 1.
We've always had this issue - however, we face it in P4 SCM.
I guess the problem would be the same, anyway - your project may not be detected as an Android project.
First create a new Android Project. Now, go to Navigator in Eclipse (Window -> Show View -> Navigator) and open .project file - copy it's contents and paste in your (imported) project's .project file. This should fix it.
Make sure to make the required changes (the project name is the only change we usually make) after copying.

How to get PhoneGap 3.5 Android Hello World to work in Eclipse?

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.

R.java not being generated for new Android project

When I create a new android project in Eclipse, and I choose to have a default main activity, my R.java file does not get generated.
I have seen some questions online and on this site about R.java not being generated but all are due to some manual action/mistake that had to be corrected during the development of the application.
However, does anyone know why R.java would not get generated for a brand new android project, where I have made no manual modifications whatsoever?
I think your problem is just the latest update of the SDK.
Test the following operations on two projects :
In the project properties (eclipse) -> java build path -> order and export make sure that all your jars in the libs folder are checked.
And "Android Tools -> Fix Project Properties"
And "Project -> Clean"
I hope you have helped!
ADT version 22 requires that you install "build tools". To get it to work i had to update:
SDK Tools
Platform Tools
Then install:
Build Tools
This link recommends you add build tools to your environment path. I had to do the following before the R.java was generated:
Append build tools to PATH environment variable
Restart Eclipse.
Make sure your project is free of errors and problems. You can use Windows-View to find and rectify them. Common mistakes are in the layout files.
Check the AndroidManifest file and see if the activity names match the classes in your source folder. Clean and rebuild.
R.java creates every time when you create android project first time r.java created by default
so check for the errors and clean the project.

Importing example projects using Android into Eclipse Helios fails

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

Creating an Android Test project in Eclipse

How do I create an Android Test project in Eclipse in the target project's /test directory?
Note: I'm just doing my own Q+A for people according to the Stackoverflow FAQ on answering your own question.
I am using Helios with the latest current version of Android (10.0.1)
The Android Testing fundamentals recommends you
place the tests in the same project folder as your src folder. Some people have recommended that you create a new test project in its own folder so it doesn't get packaged into the apk.
I looked inside my apk and I don't think the test stuff was included (but I could be wrong). I like having it in the same directory as its more convenient for revision control - you don't need to sync two projects each time.
Assume we want to create a test suite for the MyAndroidApp project
Goto File.. New.. Other.. Android...Android Test Project
Set "Test Project Name" to MyAndroidAppTest
For Test Target, choose "An existing Android project".. Use the Browse button to select MyAndroidApp
Unselect "Use default location". This changes the location to be inside the MyAndroidApp project under the tests directory
Click Finish
When it is being created, if you get a An internal error occurred during: "Refreshing workspace". error (or other errors) just ignore it. Click OK.
-Clean the MyAndroidApp project
Even though the project is in the <workspace path>/MyAndroidApp/tests directory it will appear as a normal Eclipse project in the package explorer.
Clean the MyAndroidAppTest project.
This worked for me.
EDIT
If you upload to SVN in Eclipse (by syncing the MyAndroidApp project, not the MyAndroidAppTest project) you need to do a little more (I've just done it now).
So when you update your other working copy it will pull down the /tests directory.
The MyAndroidAppTest project does not automatically show up in the Package Explorer.
So you need to go to File.. Import...Existing Projects into Workspace....
Then select the root directory by browsing to your <workspace path>/MyAndroidApp/tests directory and click Finish.
I found here a very detailed solution to this problem. It seems to be an ADT bug.
http://jonblack.org/2012/11/24/creating-an-android-test-project-within-a-project
Still, when I import the test project back into the workspace at Step 5 I get the following error message:
java.io.FileNotFoundException: C:\projects\MyApp\com.myapp.test-test\project.properties ( The system could not finde the file specified ).
I simply closed the error dialog and the test project appeared in my workspace at the same level as my android project, but the location was correctly set to MyApp/tests.
So I wrote a test, run it and it worked.

Categories

Resources