I'm trying to import an Cordova Ionic project in Android Studio to modify some things and try to solve some bugs but I can't.
I never work with Ionic before and I tried to follow some tutorials about how to import Ionic into Android but no one works for me.
In all of them you have to go to Android Studio > Import Project (Eclipse ADT, Gradle, etc.) and then select a folder called platform and then the Android Gradle.
But the thing is that in my project I only have this folders: hooks, css, www.
My highlighters to the problem above are:
To open a Cordova for Android project in Android Studio:
Launch Android Studio.
Select Import Project (Eclipse ADT, Gradle, etc).
Select the Android platform directory in your project (/platforms/android).
For the Gradle Sync question you can simply answer Yes.
Once it finishes importing, you should be able to build and run the app directly from Android Studio. See Android Studio Overview and Building and Running from Android Studio for more details.
Refs:
https://cordova.apache.org/docs/en/latest/guide/platforms/android/
https://www.codeproject.com/articles/1068176/step-by-step-guide-to-build-ionic-hybrid-app-using
For the theory behind the bove logic and possible bunders you may make, please see my answer to the following question:
Building Ionic framework in android studio
You dont have to import the Android Gradle. You have to previously do a
ionic platform add android
ionic build android
and then import your platforms/android folder
- In Android Studio
Choose File->Settings
Navigate to Plugins Tab
Choose Install JetBrains Plugins
Search for Phonegap/Cordova Plugin
Click On Install the Plugin
And Restart Android Studio
- Open IONIC Project in any editor
Run this Command
ionic cordova prepare android
It will Prepares the Ionic Project for Android
Then run this command -
ionic cordova build android
It will Builds the Ionic Project for Android.
3.Open Android Studio
Choose File > New Project > Import Project > Choose the android folder of cordova
directory > ok
Run the project with Android studio.
Related
I currently use Cordova CLI on Windows to build hybrid Android apps. I am in the process of moving my development mover to a headless Ubuntu server. Getting java, NVM, Node, Android SDK and Cordova CLI installed on Ubuntu has not been a problem. Having done so and created the customary Cordova hello world project,
cordova create hello com.example.hello HelloWorld
I proceeded to add the Android platform
cordova plaform add android
and then attempted to build
cordova build android
at which point I was told
Error: Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio
Installing Gradle by following the instructions given here - I am NOT installing Android Studio and am working on a headless Ubuntu machine so automatic Gradle installation is not an option - is not a problem. However, it is not clear to me which version of Gradle I should install.
I do not want to break my current Cordova project so I am trying to replicate the current Windows/Cordova CLI setup as closely as I can
Node 8.9.2
Java 8
Gradle ???
Dipping inside the gradle-wrapper.properties file in my existing project I find
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
I have noted that when I compile the project at present there are some ominous warnings about features to be removed from future versions of Gradle that are shown. I could experiment with using gradle-2.10 but it is not entirely clearr to me that it would indeed be the right version. Hopefully, someone here will be able to point me in the right direction.
First, clean up the project
cordova clean android
Then, force the cordova to use the distribution url with the version you want, in this case: gradle-6.3
export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL=https\\://services.gradle.org/distributions/gradle-6.3-all.zip
Then, build your application.
cordova build android --release
I'm trying to create a Ionic project.I build the project successfullyionic build androidThen I import the folder platform/android in android studio as the answer told me on Internet.But the answer is about ionic1.The folder platform/android/assets in an Ionic2 project is totally different from an Ionic1 project.There is no any html pages in assets folder but index.html.
Does anyone know the right way to develop an Ionic2 project in android studio?
When you build a project using Ionic 2, it bundles all the code into a file called main.js using Browserify, which you can find in /assets/www/build/main.js. This process was not included in Ionic 1, hence the difference.
With this scenario, I am not sure how to get it to work with Android Studio, because the Ionic project is not an Android Studio project and disabling the bundling process does not seem like a great idea.
Is there a reason why you are using Android Studio to develop your Ionic app? Why not use an editor or IDE that is more specialized for editing web apps? For example, Ionic has a great integration with Visual Studio.
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?
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).
All the answers above seem to refer to the cli. However, to actually have your project in android studio so that you can harness the power of the android studio, this is what I would suggest you do:
Please see my most relevant answer here...
Building Ionic framework in android studio
We have some troubles on importing Ionic project to android studio because we have add android platform with SUDO command, and because of it, android studio dont have access privileges to read files.
In my case just do sudo chmod -Rf 777 ionicFolder android studio can import project successful.
I hope this help some one with this problem.
I have downloaded Phonegap from CLI (working on windows7) and made a project from command line
phonegap create hello com.example.hello HelloWorld
and built it
phonegap build android
When i import project (project/platforms/android) in Intelijj and try to build it, it gives me this error
java: duplicate class: org.apache.cordova.BuildConfig
Any advice?
The steps that I did to import project in IntelliJ, after I built the application with "cordova build":
Import project
select "PROJECT_FOLDER/platforms"
Import project from external model "Eclipse"
In select Eclipse project, select all.
Import JDK and SDK (JDK 1.7 and SDK Android API 17 and 19 in my case)
Import Android Dependencies From Property Files (Add dependency helloworls --> helloworld-cordovaLib) OK.
At last this build and run without problem to me.
There are an issue with IntelliJ and Maven, maybe you can apply the same solution.
http://youtrack.jetbrains.com/issue/IDEA-94901
1.) Delete the "gen", "target" and "out" folders
2.) Revert the changes within the "ipr" and "iml" files
3.) Start IntelliJ 11.1.5 EAP / 12 EAP
4.) Open the pom file
5.) Right click -> "Maven" -> "Reimport"
6.) "Build" -> "Rebuild project"
A better workaround (tl;dr): Don't do the 'cordova build' step from the Cordova workflow (Getting Started Guide for Android)
We ran into this issue while doing Cordova training for our students. The recommended tool from developer.android.com switched from the Eclipse ADT Bundle to Android Studio, so we made the switch.
Unfortunately, you can't follow the same workflow. The Cordova 'Getting Started' guide for the Android platform spells out the commands to execute from the command line. But, they are for the Eclipse platform. One step needs to omitted for it to work with Android Studio.
One of the links above (http://www.tricedesigns.com/2013/05/16/phonegap-android-studio/) shows the correct workflow, but if you're used to the Cordova workflow, you may just assume it's the same and complete the steps in the same way. However! Omit the 'cordova build' step. Building the project (instead of letting Android Studio build it) causes Android Studio to get the error from the question.
The accepted answer above didn't work for us, because when we attempt to import the project, there is no 'Import project from external model "Eclipse"' option. This, however, worked just fine. Hope this saves you the hours we spent looking for answers/troubleshooting.
I've created by command line a new phonegap application.When I try to get it by eclipse from android existing code it can't recognise as a android project.
Have I build my phonegap app before?
Phonegap project's folders are:
.cordova
hooks
merges
platforms
plugins
www
phonegap create [optional params] will setup a blank project space. To add platforms to this project you must run phonegap platform add [ios/android/wp8]. Then depending on the platform and how you wish to develop it, you run either phonegap prepare or phonegap build.
In your case, since you wish to import to Eclipse, you will want to run:
phonegap platform add android
phonegap build
Then in Eclipse you can browse to /PROJECT_PATH/platforms/android and import your project.