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.
Related
I try to import my cordova ionic project to eclipse as an existing android application but it was undetectable? Any idea why? I could run my app in android phnoe using 'ionic run android' but why it can be imported to eclipse?
I also installed android studio and it has the same problem. I don't have a clue why is this happens..
Remove all CordovaLib that exists inside eclipse and import it again. It works 100% most of the time. Second time you import the project you will enable import your project with CordovaLib. It happens because there are existing CordovaLib inside your eclipse.
You have to choose the platforms/android folder when you want to import in eclipse, not the root of your project.
Eclipse only knows the android project, but not the cordova project.
And then select both your app and the CordovaLib projects.
But be aware that changes made in /www will only take effect in eclipse after you rebuid the project.
Or you can use eclipse project properties to unhide assets/www an in that case be aware that any changes in assets/www will be lost if you use the cli to build your project (and the same goes for any change in platform/android).
That's why I only use eclipse when I need to debug (mostly for plugins).
I faced a very same issue,
Please make sure - you are importing the project using already existing android code under the Android tab in import option. Not with already existing project option in general. This one fixed my issue,
Hopes this one will help some to save some valuable time ...
I'm trying to migrate from using Eclipse for my Android-project to the new Android Studio, and I'm having an issue related to Gradle.
What I want is for me to push the latest Eclipse-build to Github, and then be able to pull it down in Android Studio, having the latter automatically convert the project to a Gradle-build. If I'm reading the documentation right, the Android Studio import is supposedly able to do this.
When importing, I can choose between "Create project from exisiting sources" or "Import project from external model"
If I choose the first option, the project won't use Gradle (as far as I can see). If I choose the second, it seems to be looking for an already existing gradle buildfile "build.gradle" in my project.
So - Should I download a Gradle-plugin to Eclipse and make a gradle build-file there, or am I doing something wrong in the import?
It seems the only other questions I can find on SO is about importing and Eclipse export or simply how to pull a project from Github in Android Studio.
Thanks :-)
Importing and converting an existing Eclipse project into a Android Studio Gradle project is quite simple :
File -> Import Project (in Android Studio)
Select the manifest of your Eclipse Android project.
Done.
There may be some dependacy management to deal with.
You can also take a look here :
How do you import an Eclipse project into Android Studio now?
How about this:
clone repo to location 1
export from eclipse
import to android studio in location 2
copy the .hg files or whatever's applicable from 1 to 2
commit from location 2 including deleting eclipse files
Now the repo will have the android studio project and not eclipse.
I am finding it hard to run the gradle sample projects in Android Studio, getting lots of errors, found solutions for few errors in stackoverflow but its killing most of my time, Most of the new libraries are built using gradle, is there a way i can convert the gradle so that i can import in eclipse like general android-eclipse project? i tried the tutorial posted here
but most of the time its not working, i wanna try New material design samples available form github , can some help me importing them in eclipse
Try installing gradle integration to Eclipse from here: http://dist.springsource.com/release/TOOLS/gradle
You can choose only gradle during installation. Then Import / Gradle project, select root folder and press "Build model" for getting list of gradle projects. After selecting your project it will generate eclipse project file and import it. Then you can use your projects as usual (build, run etc).
As I wrote down here as it was relevant for LibGDX projects, Libgdx 1.3.0 doesn't build eclipse files
The new ADT 23.0.2 does not allow installing the Gradle Integration Tool directly from http://dist.springsource.com/release/TOOLS/gradle (or at least it did not for me), you need to go to Help -> Install New Software -> Work With -> Juno -> General Purpose Tools -> Marketplace Client, and then search for Gradle and add the Gradle Integration tool (not the 4.4 one).
Then just use Import -> Gradle, press Build Model, then OK and it should work.
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.
There are only 3-4 articles on how to use Android Studio with Phonegap.
The problem is that these are all written for lower versions from Android Studio (<0.8) and now you can't import Phonegap projects into Android Studio without having multiple errors.
Has anyone achieved it to import a Phonegap 3.5 project into Android Studio 0.8+ and will share his/her knowledge?
Edit:
Ok if you don't have errors then you can describe the way you do it!
My steps:
phonegap create projectname id projectname
change directory into projectname
phonegap build android
-- so far no problems
start Android Studio
"import project"
choose projectname folder
apply the rest steps with next and finish the import
Android Studio now has imported my project
try to test the new project by go to "Run -> Run..."
add a new "Android Application"
BUT THEN in the tab "General" you have to specify a "Module" otherwise you can't start the application
Ok and from here on I stuck.
I tried to do "Build -> Make Project" but this ends with multiple errors while Android Studio tries to compile the app.
I think the Gradle has conflicted with ant because they will generate same files. I delete the ant-build files then it works. Hope it be useful.