Phonegap project doesn't compile - android

If I create a new Phonegap project, like this:
phonegap create . com.something.test "Test"
phonegap build android
And then import this into Android Studio, via "Import Project" -> "Create project from existing sources" -> Next (lots of times) -> Finish, and then just try to build without any modifications, I get this:
Error:(4, 14) java: duplicate class: org.apache.cordova.BuildConfig
Am I missing a step or is there an issue with Cordova 3.6.3 / Android Studio 0.5.1 ?

Interestingly, from Project Settings -> Modules, I analysed CordovaLib and Android Studio told me there was no dependancy for it, so I chose to remove. Now compilation seems to work!
I'm not sure why this needs removing but hopefully it'll help someone else too.

Related

Cant import OpenCV module in android studio

I've been trying to import Open CV module to android studio exactly as many tutorials online told me to but it wont work. I googled the issue a bit and found a solution to choose the sdk folder as the directory and not java but even that dosent work.Im using Android Studio v4.0.1 and the latest version of OpenCV. Help.
First of all make sure your sdk folder in your downloaded opencv sdk contains a build.gradle file. If your downloaded sdk doesn't have build.gradle try another version of opencv sdk, Unless you have to select java folder in the opencv sdk and after that copy jni files into your project tree.
The easiest way to import OpenCV sdk into your project is as follow:
Create an Android Project
File -> New -> Import Module -> path to OpenCV/sdk/ -not java folder! (opencv 4+)
File -> Project Structure -> add OpenCV as 'Module Dependency' of 'app'
Clean Project
Done! no need to copy jni libs and other things.
Importing opencv to androidstudio
->First download opencv from https://opencv.org/releases/
for your current using android studio version,and extract it.
->open android studio create new project if project is already
exist follow the below.
->in android studio choose option in MENU->File->Import
Module here please select the your opencv-android directory
till sdk selection
eg:("E:\stardev\OpenCV-android-sdk\sdk") and
then finish, if your downloaded same version it's good to go
else change the build.gradle setting from opencv build.gradle
and sync.
->after this to add as a dependency in android studio
Choose
Menu->File->Project Structure->dependencies,
select app from tab and add(+ icon) from menu select module
dependency and select sdk from here.
->to test goto your project activity and
(import org.opencv.core.Core)
If you are using Arctic fox and still facing this issue, This Solution worked for me.
If your next and/or finish buttons is still not clickable after adding the right path
https://stackoverflow.com/a/68738767/12052997

How to get PhoneGap 3.5 Android Hello World to work in Eclipse?

I used PhoneGap 2.* without any problems, but now I cannot, for the life of me, get a basic “hello world” to work. I want to use the “platform-centered workflow” because my 2.* projects have a lot of customization.
Here’s what I’m doing:
I’nm on a Mac and have a folder ~/desktop/android with all my Eclipse projects.
Download https://www.apache.org/dist/cordova/platforms/cordova-android-3.5.0.zip
Unzip it and put it in ~/desktop/android/cordova-android
Run /users/me/desktop/android/cordova-android/bin/create /users/me/desktop/android/hello com.example.hello HelloWorld
The project is successfully created!!!
As per the PhoneGap docs, I go to File > New Project > Android Project from Existing Code and select the “hello” directory.
I also check “copy projects into workspace” because it doesn’t work if unchecked.
There are actually two projects HelloWorld and HelloWorld-CordovaLib. I check them both.
If I try to run HelloWorld as an Android application, I get the following errors:
Config cannot be resolved
CordovaActivity cannot be resolved to a type (x3)
The import org.apache.cordova cannot be resolved
The method on Create(Bundle) of type HelloWorld must override or implement a supertype method
After looking over some previous questions, I decide to import cordova-android using File > Import > Existing Project into Workspace
Right click on the new Cordova folder in Eclipse and under Android make sure is Library is checked.
I clean and build everything.
I now get the error “the project cannot be built until path errors are resolved”
What do I need to do to get a basic hello world PhoneGap 3.5 working???
I figured out that the problem was creating the project in the default Eclipse project directory. I created the project in a new directory:
/users/me/desktop/android/cordova-android/bin/create /users/me/desktop/mynewfolder/hello com.example.hello HelloWorld
Then in Eclipse, I did File > New Project > Android Project from Existing Code, check both projects but did NOT check copy projects into workspace.
Now I see that the HelloWorld-CordovaLib is green checked under libraries. After a few cleans and builds it all works.
As mentat said, I did not need to import the conrova-android project.
You don't have to import cordova-android. Make sure you have a reference to HelloWorld-CordovaLib by right click on HelloWorld project, Properties -> Android - Library list -> Add
It should have a green check for CordovaLib. Also try project -> clean the project, Eclipse needs it often.

Cordova ant jar not available

Cordova 3.3.0 installed from fresh and PATH fixed with visibility to tools etc.
Build a new bare application
Add android platform
now it starts to go awry -
Following instructions to import to Android Development Tools ( Eclipse ) I get TWO projects created
HelloWorld and HelloWorld-CordovaLib
HelloWorld has errors as it can't see/does not have the the cordova.jar file ( assuming this from past experience )
HelloWorld-CordovaLibs is whats missing from the HelloWorld project all the source to Cordova
Assuming that I need the jar file I dig around and try running ant jar from within the android part of my project
Running ant jar fails -
Target "jar" does no exist in the project "HelloWorld"
which is an ant error telling me it doesn't know how to build target jar.
look at build.xml in the android directory confirms this - no section on "jar"
A bit more digging on the net and the Apache Cordova git repository seems to intimate that I should have another file build.xml inside a directory 'framework' with the jar target defined.
Ahhhhh - no framework directory anywhere.
Can anyone work out where this is all going wrong before I tear any more hair out?
I followed this guide to create a Cordova 3.3.0 project, import it into Eclipse, and successfully run it on a device from Eclispe: http://cordova.apache.org/docs/en/3.3.0/guide_platforms_android_index.md.html#Android%20Platform%20Guide
You are right that it imports "HelloWorld" and "HelloWorld-CordovaLibs". This is because of https://issues.apache.org/jira/browse/CB-5232, which makes Android now use the CordovaLib instead of the .jar for a variety of reasons (see the bug report.) You should import both projects into Eclipse (I'll change this in the documentation).
If you follow that guide you should be fine. You don't have to build a .jar anymore.
steps
1- after create the project i import both "hello" and "hello-cordovaLib"
2- i remove the reference to "hello-cordovaLib" from "hello"
3- build the "hello-cordovaLib"
4- restore the reference to "hello-cordovaLib" from "hello"
5- clean "hello" and run
In short .... The ide ( either eclipse or ADT ) needed the initial build of the sub project to allow the HelloWorld project to 'see' the HelloWorld-cordovaLibs project.
What solved my problem on HelloWorld project in my ADT is :
I cleaned both the HelloWorld and the HelloWorld-cordovaLib.
Right clicked on HelloWorld-cordovaLib ->properties->Android and verified
it the isLibrary is checked.
I right clicked on HelloWorld proj -> Properties ->Android -> The "is Library part" had Cordova with red check on it then I clicked on "Add" button and again added Cordova to the project which came with "green check" and then removed the red checked cordova.
Cleaned the projects and now its working fine.

Android Studio Marks syntax as error, but gradle compiles

I have a project in Android Studio which compiles with Gradle.
The general file structure is
MyProject
- MyProjectSource
- Libraries
- ActionBarSherlock
My project is built with Gradle and will compile without issue. However in the lines within my activity where I include a component from ActionBarSherlock, Android Studio marks it as an error.
I have noticed that Android Studio has also generated .iml files. So my question: Does Android Studio ignore the gradle build when assessing whether something is valid syntax or not?
Obviously this is not a project blocking problem but it does slow velocity not being able to take advantage of the full set of tools Android Studio has to offer.
Thanks in advance for any help.
These are not errors actually, this a bug in Android studio( 0.4.2 ) for resolving the symbol and fixed for the next release( 0.4.3 ).
To get Rid of these until the release do the following
Clean your project using Build > Clean Project
Close your Android Studio
Take Backup of your project
Delete all .iml files inside your project
Delete content of .idea directory
Open Studio and wait until it completes the sync with gradle
Also verify if you are seeing any error in File > Project Structure . If there is any error saying "Dependency Not Added "click on that and using red bulb on right side Add them to dependency.
UPDATE
Android Studio 0.4.3 is available on Canary Channel Now.
UPDATE: #laochiv, I have found that cleaning manually the folder .idea/libraries and clicking afterward on "Sync Project with Gradle Files" solves the problem. Apparently this Sync does not remove elements, but keep the old ones and add the current ones. Probably a bug to report :)
I am having the same problem. However, I am using ABS directly from Maven.
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.+'
}
Even the ABS Gradle Sample application marks a syntax error, although it compiles.
However, in another computer everything is working perfectly. I can not think of different conditions in each scenario.
"Does Android Studio ignore the gradle build when assessing whether something is valid syntax or not?" Yes. Android Studio imports the project configuration but runs its own compiler as you are editing and saving (you can even change it to the Eclipse ECJ compiler). The true authority on the build is Gradle, and AS is still in beta. You can try to run the gradle resync or close and reimport the project. I have had to manipulate AS like this many times, especially after making edits to build.gradle.
Edit: I have found it better to use ActionBarSherlock as a gradle dependency rather than a library directory.
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
You will need to use the SDK manager and install the local maven repository.
But it is possible to eventually get rid of these compile errors, as long as your build.gradle doesn't create any extra sourceSets that AS doesn't understand; try not to deviate too much from the android gradle plugin examples.
Also, I've been running the Canary updates of AS for the latest and greatest.
I don't know how to add a library using MavenCentral. I follow these steps to include a library
Add library in App_Name/App_Name/libs folder.
In App_Name/build.gradle add this
dependencies {
compile ---
compile files('libs/fileName.jar') }
./gradlew clean
Make sure your Android studio is updated.
Go through the link and it worked for me.
1.) Choose File option from menu on left top side of android studio.
2.) Select the option : "Invalidate Cache/ Restart.." It will open an dialog.
3.) Click on the first button with option : "Invalidate and Restart"
4.) It will close the studio and restart it. Start indexing of the project.
It resolved my problem
Go to File -> Invalidate Cache/ Restart -> Invalidate and Restart
Source
https://www.youtube.com/watch?v=FX_gCTpqhwM
I had this problem in Android Studio 4.2, it might be fixed on 4.3
I have noticed that adding some dependencies did not attach the classes.jar to the dependency, so Gradle recognises everything but the IDE doesn't. To fix it:
Open Module Settings of your project
Select the dependency that has the error
Click Add (+) for that dependency (bottom of the pop up)
Navigate to your-project/build/exploded-bundles/your-dependency/classes.jar
The IDE should recognise the files now
Hope it helps
I had this today and gradle update/sync didn't solve. But updating to latest version of Android Studio 2.2 update 5 fixed (was on 2.1).
Here i'm talking about android studio version v3.1.2 where this same issue happened.In later android studio version(above 3.0.1) this issue again rises. So, I solved this by going through few things and here is how
Close android studio first
Navigate to your Project Folder
Delete .gradle and .idea folder (.gradle and .idea is hidden files. so make sure you tick Show Hidden Files in your File Explorer option to see these files
Open your project in android studio now
This Time another issue (unsupported module) will arise, but don't worry. I got you
Goto File in android studio and hit Sync Project with Gradle Files
Tada..! you're done now!
Simplest Solution
Comment/Remove the dependency which is showing syntax error & Sync Project.
Uncomment/Add again & Sync Project.
Yeah! error gone...
Before
After

Android Studio Error "output path is not specified for modules"

I just recently upgraded to the newest version of Android Studio (0.1.1), but I also used Android Studio to relocate my project to my Dropbox folder. So, I'm not exactly sure which one is causing this problem. When I build or try to run my project I get this error:
Cannot start compilation: the output path is not specified for modules
"actionbarsherlock",
"EmPubLite-EmPubLite".
Specify the output path in Configure Project.
I can't find any reference to "Configure Project" and the Project Structure option under File no longer works in this release.
Solution for Android Studio version < 1.0 :
You just have to go to your Modules settings > Project and specify a "Project compiler output"
and make your modules inherit from project. (For that go to Modules > Paths > Inherit project.
Or you can specify your output for each module if you want.
In order to do so you just need to follow this steps:
Open Project structure (F4 on one of the modules in the project explorer)
Click on Project tab on the left
Define "Project compiler output:" as YOUR_PROJECT_PATH\out (or any folder you want)
Click on Modules tab on the left
Go over all your modules and verify that under the Paths tab the Compiler output is set to "Inherit project compile output path"
I ended up re-importing the project using Gradle and it's back to normal. Very weird issue.
this is a problem that I face in case I open my phonegap project with Android Studio and Webstorm.
They are IntelliJ-based project and I guess they are both writing the files in .idea
Reimporting the project is the solution.
got same error while using studio feature to import from GitHub repository.
I deleted the whole project and .. cloned it using git terminal and imported as new project ... studio prompted to add VCS root, accepted ....everything was fine afterwards. As #lordhong prompted.
I found this:
http://www.chrisdew.com/blog/2013/07/17/android-studio-nosuchmethoderror-lazystringarraylist/
it is realy help for me.
Thus, in my case, the problem was to have two libraries:
protobuf-2.4.1.jar
and new protobuf-2.5.0.jar
it resulted error:
APK path is not specified for module “Example-Example”
To correct this, rename file protobuf-2.4.1.jar to protobuf-2.4.1.jar.disabled
mv protobuf-2.4.1.jar protobuf-2.4.1.jar.disabled
How I finally managed to fix after hours!
File -> Project Structure -> Facets -> choose module's facet -> Packaging. Enter in APK Path absolute path to apk to be created: C:\workspace\MyCompany\MyProject\myProject.apk
Press ok and run your project

Categories

Resources