I am trying to create a Cordova project. After creating the project cordova create myProject
I would like to open it in Android Studio. The problem is ... it doesn't work.
The CordovaLib will not build with various errors package android.* does not exist
.
Does anyone know how to import a cordova project in Android Studio?
Cordova for Android requires the Android SDK which could be installed on OS X, Linux or Windows operation system. See the Android SDK's System Requirements. Cordova supports Android 4.0. x (starting with Android API level 14) and higher.
Unfortunately the accepted answer is a bit out of date. Using Cordova v5.3.3 (it probably works on all versions > 5) it is much the same process a building and then entering XCode for an iOS application now - the build system has moved to gradle.
Before opening in Android Studio
cordova build android
Then just open up the project using File > Open and pointing to the (yourProjectDir)/Platforms/Android directory.
If you are using an older version of the cordova android platform you might need to run
cordova platform android update
To get moved to the gradle build system which is compatible with the current version of Android Studio
Make sure you import the "platform/android" directory underneath your cordova project (and you want to Import Project, not Open Project).
You will at least need to run
cordova prepare android
before doing the import
cordova build android
will also work, but it will create some ant directories which will not be used by Android Studio and you will have to actively ignore the files when importing otherwise you will get extra libraries in your project). Although I haven't imported a Cordova app into android studio recently, it definitely works in the Community edition of Intellij which Android Studio is based on (I did it yesterday with a project built from scratch with Cordova 3.5). I can't think of any of the additional features in Android Studio that would be useful that aren't in Intellij, as most of the additions which haven't been backported to Intellij are in the preview space which isn't going to work with Cordova anyway (all it is going to preview is a blank webkit view).
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