I'm trying to get a new PhoneGap application setup and running inside Android Studio with the Gradle build system.
At the moment I have successfully created the PhoneGap project and imported into Android Studio. It all appears to be working fine, but I cant work out how to move it to the Gradle build system, or even if its possible.
Can anybody help?
Open your gradle. properties file in Android Studio. Restart Android Studio for your changes to take effect. Click Sync Project with Gradle Files to sync your project.
Open Android Studio and choose "Import project" and choose to use Gradle as the external model. Pick your settings. gradle file as the Gradle project. [Optional] Set your "Gradle home" folder (so the text turns black instead of gray).
Android Studio uses Gradle, an advanced build toolkit, to automate and manage the build process, while allowing you to define flexible custom build configurations. Each build configuration can define its own set of code and resources, while reusing the parts common to all versions of your app.
I managed to do this.
You need Android Studio and the Eclipse ADT version, as well as Cordova/PhoneGap all set up.
Select both your Android project and the CordovaLib project to export and click Next.
Once this completes, open Android Studio.
After the import, you may get some warnings about a newer gradle version in use, just check your settings and it seems to work itself out.
At this point, you should have a project structure that is your main project, but with CordovaLib as a module.
Now you can open the build.gradle file in the main project directory and change it to this:
buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.11.+' } } apply plugin: 'android' android { compileSdkVersion 19 buildToolsVersion '19.1.0' sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] resources.srcDirs = ['src'] aidl.srcDirs = ['src'] renderscript.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] } } } dependencies { compile fileTree(dir: 'libs', include: '*.jar') compile project(':CordovaLib') compile 'com.android.support:appcompat-v7:19.+' }
You should now be able to convince Android Studio to compile.
An extra tip would be to create a script to run "cordova prepare" and add that to the module's run configuration as an external tool. Make sure to synchronise the whole project before deploying the APK to a device or emulator.
I am new to Android Studio and still getting used to the AS project structure and Gradle.
Using Cordova 4.1.2 Android Studio 1.0.1
1) I created the app using the Cordova CLI:
cordova create CordovaAndroidApp
cd CordovaAndroidApp
cordova platform add android
this version of Cordova created the build.gradle and settings.gradle files.
2) From Android Studio splash screen I selected "Start a new Android Studio project" On the second screen I checked the Phone and Tablet box; on the third screen, I chose "Add No Activity"
3) In this new Android Studio application, from the Project view in the left panel with the top level of the project selected, I selected File -> Import Project. In the popup "select Eclipse or Gradle Project to Import", I chose to the Cordova project directory, clicked down to the platforms / android directory, and selected the build.gradle file, then OK.
I was able to build and run the basic Cordova project (just the splash screen) with no problem.
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