I'm trying to implement maven into an existing android project.
I've done so through the context menu > Configure > Convert to Maven project. And everything seems okay, no warnings or errors.
But when I try to run the app (just like before) I get:
12-31 10:16:57.423: E/AndroidRuntime(14242): java.lang.RuntimeException:
Unable to instantiate activity ComponentInfo{xxx/xxx.MainActivity}:
java.lang.ClassNotFoundException: xxx.MainActivity
I've followd all the instructions on implementing m2e and everything looks like it should work.If I don't convert the project to a maven project, the app runs fine.
Any suggestions where I'm failing?
This is what my pom.xml looks like: http://pastebin.com/ByXA0BP4
This took me ages to resolve and it was the OP's answer which guided me.
After enabling Maven for the project, you need to disable "Allow output folders for source folders"
Steps:
Project Properties -> Java Build Path -> Source Tab -> Untick "Allow output folders for source folders" -> Click OK
I also noticed that I got the following message in the console, which led me down a rabbit warren of false leads:
trouble writing output: already prepared
I figured it out myself.
After converting the project to a maven project, right click on the 'src' folder and chose Build path > Use as Source Folder
Now the project runs fine
ClassNotFoundException is simple, the respective jar is not there in class path.I checked your pom.xml, but i was unable to relate any dependency that could have xxx.MainActivity.
So just ensure that respective jar is there as dependency artifact that contains MainActivity. If it still would not work, try copy pasting the jar manually into deployment\lib folder and it should work. Another option could be to debug your current CLASSPATH location and see if your jars are there or not.
Also by default Maven probably would not update dependencies. You have to right click->Maven-> Update Project to download any newly added dependencies in your pom.xml. There might be an error downloading dependency for that you have you to find the right repository or download the jar locally and install it as local artifact.
Thanks
You may check if the virtual or real device where you are testing the app is actually compatible with the target Api of the project. Change it to the proper one and check again.
Related
I know that there are a few questions here on SO that are quite similar to mine but still none of the answers there could really help me.
The scenario is this: I am using Eclipse + ADT to develop an Android app. I recently moved to Maven for dependency and build management, to make it easier to include Spring for Android, Google Play Services, etc. At the moment building with Maven (from the command line) works but running the app with Eclipse does not work anymore.
When I:
add a new dependency to pom.xml
do mvn eclipse:eclipse to make the new dependency available in Eclipse (that's the correct to do it, right?)
I get this error: "/foo/gen already exists but is not a source folder. Convert to a source folder or rename it."
I tried several ways of making this error go away, but I all I get is other errors:
When I:
go to Properties > Java Build Path (Source tab) > Add Folder... > check gen > OK > OK
this error is replaced by "The type BuildConfig is already defined".
So I:
go to Properties > Java Build Path (Source tab) > select Foo/target/generated-sources/r > Remove
Ok, no errors now, but when I try to run the app on my device, I get:
"Caused by: java.lang.ClassNotFoundException: Didn't find class "com.bar.foo.MainActivity_" on path: /data/app/com.bar.foo-1.apk
Checking in bin/classes however, I find that MainActivity_.class is indeed generated - but somehow it is not included in the apk, I guess?
Note that the I can also see the classes from my source code, so the following, for example, works:
BrowseNodesActivity_.intent(this).start();
When I check Properties > Java Build Path (Order and Export tab) I see that the folder /.apt_generated is at the very bottom of the list. Is that a problem?
By the way, the error is exactly the same if I remove all the target folders generated by Maven from the build path so that the build path (Source tab) shows only src, gen and .apt_generated
Is there a way to get this approach - using Maven for dependency and build management but not using any Maven plugins in Eclipse - to work?
Anyway, I also tried the following approach as was suggested here:
https://code.google.com/p/maven-android-plugin/issues/detail?id=30
I installed Eclipse Maven support by:
installing m2e from http://download.eclipse.org/technology/m2e/releases
installing the Eclipse Marketplace
trying to follow this how-to from m2e-android (SO won't let me post another link)
I go to Eclipse Marketplace
type "android m2e"
find something called "Android Configurator for M2E" (is this same as the "Android Connector"?) and install it
right click the project > Configure > Convert to Maven project
Then I get an error in my pom.xml - "Plugin execution not covered by life cycle ... com.jayway.maven.plugins.android.generation2"
So, all in all, using the Eclipse plugins for Maven didn't work either...
Is there ANY way to get all of the components in my setup to work together somehow: Eclipse, ADT, Maven, AndroidAnnotations (and optionally m2e and m2e-android)?
You have to install the m2e, m2e-apt and m2e-android plugins for Eclipse. If you have Plugin execution not covered by life cycle errors, just apply the Quick fix for it. This error is shown because m2e-android cannot use AAR libraries, yet. Enable m2e-apt to configure JDT to use the AndroidAnnotations processor, you can read it here. If its done, right click on the project -> Maven -> Update Project. At this point your app should compile, but the generated classes may not included in the APK. To resolve that, modify your .classpath. The correct classpath is here in the workin_cp.xml file.
I know that there are different solutions with different libraries posted. But, could anyone help me with this one?
I've busting my head for the past couple of days, and I really don't know what to do. I already tried importing the modules in all the suggested ways from different posts. (Project Structure --> Dependencies --> Add dependencies), etc. My project does not show any errors, but when I run it, it throws me a compilation error that complains about some classes missing. The library only depends on the ViewPagerIndicator's library which I also imported.
here is a picture. Thanks!!!
NOTE:I also have tried it with Eclipse, but the problem is different there. The app crashes when I run it. When I uncheck isLibrary from Properties -> Android and erase those libraries, the app works.
Inspired by this answer, these are the steps I did:
Put the jar file (in my case, 'xxx.jar') into the libs folder of your project
Right click it and select Add as library
Type this in the dependencies part of build.gradle file: compile files('libs/xxx.jar')
Do a clean build. It can be done inside the android studio, but I also ran the gradlew.bat included inside the project folder
Now, the project should be built and run just fine.
You are referencing the library wrong. You need to add the dependency in the build.gradle file. I recommend you to read the documentation first. It's a long read, but totally worth it.
I noticed that a user uploaded the library as .aar file in his maven repo. You might want to use the library from his repo. The setup is very easy (you only need to include the dependency of the better picker library).
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
I am newbie in the world of android app development. I was creating a project Example on Android Studio. I have my LunchList.java file in src/main/java/apt.tutorial.lunchlist .Till yesterday Everything was working fine. But when I open android Studio today I got an error saying
"The modules below have been removed from Gradle structure. Check
those to be removed from the project too:"
☑ LunchList
☑ LunchList-LunchList
And there is OK and Cancel Button. I don't want to remove them. So I click cancel and proceed.
Then when I tried to run the application in emulator the emulator runs but nothing happens. And I got this error
Waiting for device.
Target device: emulator-5554 (Android)
ERROR: APK path is not specified for module "LunchList-LunchList"
I don't know what went wrong. Please help me.
[Edit: I tried unchecking both of them and click OK. But after that I'm not getting the first error but still getting the second error ]
Exit Android studio. Launch it with Administrator Privilege.
This solved the problem with Android Studio v0.1 in Windows 7.
I had the same issue, I unselected the 2 files and then received the error
"ERROR: APK path is not specified for module"
I just restarted Android Studio and reopened the project and then it worked normal again.
It is indeed a bug but there's a simple work around.
Here's what worked for me: delete .idea/ and *.iml files, then open a project again (as gradle project) - all the idea files will be recreated - and everything works fine
I had the same error with IntelliJ CE.
I fixed it by choosing "Inherit project compile output path" in the strong text imodule settings (Paths tab > Compiler output)
In my case, I imported the same project over again. Android Studio overrode the old settings. Then this error went away!
this happened when i update to 2.0. i had to change the dependencies in the build.gradle file under src dir not gradle dir. change from
dependencies {
classpath 'com.android.tools.build:gradle:0.4.0'
}
to
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
Not sure how much help this will be, but I saw that same error this morning after updating to Android Studio 0.2.0. First, I needed to modifying my build.gradle file to indicate that the correct gradle plugin to use with my project was version 0.5.0 (rather than 0.4). After modifying build.gradle, I saw the "APK path is not specified for module .." error when attempting to build. I solved this by simply quitting and restarting Android Studio.
I had the same issue and found the solution.
Stackoverflow Question
this is the same way to fix the error
Also lower down in there is "SDKs" i also had to make them match.
Name and Build Target.
Hope it helps it did me. apparently the IntelliJ is what Android Studio is.
I've found that the issue is usually if you've changed or moved the folder to a different location.
If you open up the .idea folder in AndroidStudio, have a search for any reference to the old location. If you find some, just replace with the new location. It would seem some of the lines are hardcoded.
There is a manual "how to move project" here
I moved progect, got your problem, followed this manual, got window like you and choose "OK".
And now it works very well.
It helped me to set the right SDK...
I used the one in Program Files, what did not work!
Then i found out to use the following SDK (set in local.properties):
sdk.dir=C:/Program Files (x86)/Android/android-studio/sdk
Hope this helps...
I find 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
Finally! Updated solution found here:
Android APK path is not specified for module
Open Project structure
Click on Modules tab
Expand your project and click on Android
On right side click on Compiler tab
Looking for "APK path" field
Enter your project root folder, i.e. /Users/bla/project/my.apk
Click Apply and Ok
I was looking for an ePub reader in android.I referred PageTurner. Got it's apk downloaded and it worked.
But when I downloaded it's source code from github
(as it's open source) and tried to Import the project, it gives the message that No Projects found to import even though it's pointing to the correct location.
I searched for similar questions on SO, but didn't got any help.
I guess I'm missing out libraries and some other stuff that will make this work. Note that bin and gen folders are missing at github link.I'm using Eclipse Indigo as IDE.
Any idea what's wrong here? Any help appreciated.
EDIT
1.) From suggestions, I created new project and imported it from existing source but it's giving errors at virtually every line of code.
Some of the errors are like :
Package x1 does not match with package x2
class RoboActivity not found
method not found
#Inject cannot be resolved to a type
2.) What exactly do I download from Maven site?
Which libraries are required from these.
Moreover, When I tried to install the plugin from instructions, I got
3.) this link is available for Maven Plugin but I can't find the plugin here :(
Your project is maven project. Download maven plugins for eclipse then import existing project as Existing Maven Projects. Dependencies of other jar will automatically resolved if your pom.xml file is correct.
Maven Eclipse Plugin
Maven 2 Eclipse Plug-in
instead of importing try
create new project using existing source
Hope this helps
Big update: I hadn't realized that the new ADT likes Maven even less than the old one.
Let me chime in here as the author of PageTurner: personally I don't use the Eclipse Maven plugin, but I simply generate an Eclipse project with mvn eclipse:eclipse.
If you have never worked with Maven, it's a command-line build tool similar to Ant (or Unix make). You can download Maven 3 here:
http://maven.apache.org/download.html
Once you have Maven installed, the steps to import PageTurner into your Eclipse environment are:
Download and unpack the sources
Run
mvn -Djavax.net.ssl.trustStore=trust.jks -Djavax.net.ssl.trustStorePassword=pageturner -DexcludeTransitive=true dependency:copy-dependencies
inside the source folder
Create a libs folder
Copy everything in target/dependency to the libs folder
In Eclipse, select "New Android Project" -> "From existing source" and point it to the folder you unpacked PageTurner in.
Essentially this completely leaves Maven out of the game, except to get the dependencies.
if bin and gen folders are missing no matter you can also create your own project and just copy the res,src and manifeast files from that source to your project. then just refresh your project then clean it an build it will work.
This is maven based android project. So you need to download all the dependencies first, then import the project.
Read this carefully.