A while back I've worked with Eclipse and Phonegap and I've successfully deployed a few Android apps. So now I'm trying to get the new Phonegap/Cordova app up and running in Android Studio but so far without any luck. Here's what I've tried:
1) I've generated a cordova app and added android as platform.
cordova create hello com.example.hello HelloWorld
cd hello
cordova platform add android
cordova -version
Ok this works
2) Then I start Android Studio and import the generated app and a message "Gradle settings for this project are not configured yet" appears and I press OK.
3) Then I get an error "Gradle version 1.10 is required. current version is 2.2.1" and after some googling I found a hint here and I changed a line in Gradle from 'com.android.tools.build:gradle:0.10.+'
to :0.14.+'
and now the RUN icon at the top is enabled so it seems to have fixed at least something. Although the version nr doesn't make sense to me but from what I can gather the versions are very specific.
But now I'm stuck on the error "Module android is not backed by gradle" and I don't know what to do.
Any help would be greatly appreciated.
From this link
Cordova for Android now supports building with Gradle.
To build cordova
with gradle
Right click on My computer
-> properties
-> Advanced system setting
-> Environment Variables
and create ANDROID_BUILD system variable with value gradle
Now cordova build android
will create gradle project which can be easily imported as a android studio project.
Note :
If you are behind proxy then you have to set proxy first with
gradlew -Dhttp.proxyHost=proxy.blah.com -Dhttp.proxyPort=8000
gradlew batch file will be created automatically in your directory
Okay I've figured it out so I'll just answer my own question. Hopefully it will also benefit someone else trying to do the same thing.
There are actually two build.gradle files, one in the main project and one in the CordovaLib folder. I guess CordovaLib is a subproject within the main project. So after generating the Cordova project and importing it into Android Studio an error appears
Error:Gradle version 1.10 is required. Current version is 2.2.1.
Edit the build.gradle files and make the following change in both files:
change classpath 'com.android.tools.build:gradle:0.10.+'
to this : classpath 'com.android.tools.build:gradle:1.0.0'
Btw I know the error message said v1.10 but changing it to that gives another error "Could not find.." and "1.0.0" seems to work, so yeah go figure...
Then I select Build -> Rebuild Project from the menu and it gives another error
Error:The SDK Build Tools revision (19.0.0) is too low for project 'android'.
Minimum required is 19.1.0
Clicking on the error message unhelpfully does nothing, but I again edit the build.gradle files and change buildToolsVersion "19.0.0"
to buildToolsVersion "19.1.0"
in both files. To sum up the changes see screenshot below:
Then again select Build -> Rebuild Project
from the menu, and it will give an error in the Gradle Console
Error: Task '' not found in root project 'android'.
Just ignore it, and do Build -> Rebuild Project
again and then it will give an info dialog "Language level changes will take effect on project reload. Would you like to reload project "android" now?" and press Yes.
The project will reload and is now ready to run on a device or in the emulator. :) phew..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With