No Java files found which extend CordovaActivity. when use "cordova build"
JavaAndroidCordovaJava Problem Overview
My computer is Windows 8 64bit, i install cordova and android platform for my project, I have created my project by input cordova create hello com.example.hello HelloWorld
and cordova platform add android
but when i run cordova build
, it show below error:
[Error: No Java files found which extend CordovaActivity.]
i searched the web but didn't find the solution yet, What's the problem?
Java Solutions
Solution 1 - Java
I had the same error when I cloned my repository from another project. I solved it by removing the platforms and adding it again.
remove : cordova platform rm android
add : cordova platform add android
Solution 2 - Java
All you need to do is remove platform cordova platform rm android
and re-add platform by typing cordova platform add android
, and the error goes away
Solution 3 - Java
In Eclipse or another editor, go into the .java source file under platforms/android/src/
Solution 4 - Java
I had the same issue (albeit on Ubuntu) and tried Hyperizer's answer, which should have worked... but to no effect for me. Note I had the error after upgrading cordova (from 3.0.9 to 3.4.0-0.1.3), and so my generated platforms folders were out of sync with the latest cordova version.
I found the cleanest thing to do (and this worked for me) is to remove your /platforms/android directory (as per cornelius' answer... but my focus is cordova), and then recreate with cordova so you know everything is up to date and inline with the current cordova version.
cd platforms
rm -rf android
cd ..
cordova platform add android
Your android folder is recreated, and now try building and running again.
cordova build android
cordova emulate android
The downside of blowing away and recreating the android platform folder is that you will need to re-apply any customisations you may have made to the android source...(I hadn't had to thankfully) but then you should be able to pull this from your git etc. At least now you are working on a clean and tidy up to date build.
Solution 5 - Java
This error happened when I change the package id name from the config.xml, such as io.cordova..etc to another package name, so I solved it by removing the platform of android and changed version info and package name from config file, and run command android cordova platform add android
Solution 6 - Java
Typically happens when one change the id in the config.xml file after the platform was added:
<widget id="changed-this-id" ...
To fix:
remove : cordova platform rm android
add : cordova platform add android
Solution 7 - Java
The .java file with the Activity extending the CordovaActivity must be exactly in com.example.app - as specified in the config.xml's
This changed in 3.2.0 - filed a bug report: https://issues.apache.org/jira/browse/CB-5515
Solution 8 - Java
Just on a related topic regarding PhoneGap 3.2 causing the same error, chances are that you probably messed up the app when configuring and trying to get it running initially
What worked for me was to remove the generated android platform files and just run the RUN command again. So from your PhoneGap project's home directory, do the following
cd platforms
sudo rm -rf android
cd ..
sudo phonegap local run android --emulator
I am working on a Macbook Pro with OSX version 10.9
Hope this helps someone!
Solution 9 - Java
This error comes when you changed the package id or name in config.xml, All you need to do is remove the android platform by typing "Cordova platform rm android" and re-add the platform by typing "Cordova platform add android". You can get a successful build.
Solution 10 - Java
I stumbled upon a "solution" for anyone who uses a Framework that "hides" the extending of the CordovaActivity, i.e. the MainActivity looks like this:
public class MainActivity extends GDCordovaActivity {...}
where GDCordovaActivy is your Framework Activity extending CordovaActivity.
Simply add a "foo.java" File to the project only containing a comment like this:
/** extends CordovaActivity */
As the cordova framework parses the file and doesn't recognize the comments you will be able to call cordova android prepare
etc. without any errors.
Solution 11 - Java
This issue is causing due to missing of MainActivity.Java File Generally it is residing on the below path.
[Application Name]\platforms\android\src\com
Here it should have the folder name based on the namespace you have given.
Suppose I have given namespace as com.passion.oilfreerecipes
So there should have folder passion --> OilfreeRecipes
And inside of their you should have MainActivity.Java.
It clears in my application as i clean the solution. You can copy and paste from other project and change the mainActivity.Java based on your need.
Solution 12 - Java
This can happen if your id
and android-packageName
in config.xml
do not match.
android-packageName="com.example.app" id="com.example.app"
Solution 13 - Java
I had too many customisations and did not want to recreate the platforms.
Solved this by changing the widget id
in defaults.xml
to the new package name (I changed the default io.hellocordova
into my own package structure)
Solution 14 - Java
I fixed this issue by reset the JAVA Environment.
$ sudo update-alternatives --config java
choose the number for /usr/lib/jvm/java-1.8.0-openjdk-amd64.
Press enter to keep the current choice[*], or type selection number:
To choose a default javac compiler, run the following command.
$ sudo update-alternatives --config javac
If you prefer to use a gui instead of the command line, you can execute galternatives instead and define the default versions of software with the following dialog.
$ sudo galternatives