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.
Related
Project in question is this, but it is a problem I've come across too often. Many projects seem to have a similar structure.
https://github.com/sephiroth74/HorizontalVariableListView
So again, I would like to know the quickest way to import/open the demo in this project (and have it launch) in the latest version of Android Studio.
I have tried importing the overall folder, tried importing the demo folder, but after battling with error after error for hours (in total time spent on getting projects like these to launch) I find it quicker to just create a new project and pull in all the files and resources one by one.
A step by step would be nice, if that's not asking for too much.
Ok so this one wasn't too difficult. The key was using Import project (Eclipse ADT, Gradle, etc.) or Check out project from VC as opposed to Open project.
After that there are a few errors that aren't too difficult but still very confusing for someone starting with Gradle, so here's how to fix them.
This is with the Import Project flow:
Import Project -> Select the overall folder -> OK.
First error I get is this:
This one's easy - click fix plugin link and that's done.
Next error: The SDK Build Tools revision (19.0.3) is too low for project ':demo'. Minimum required is 19.1.0
On the left you see Android view which hides the files you need when the project is not gradle-synced:
Click Android dropdown (top left on the screenshot) and choose Project or Project files. Expand until you see these three build.gradle files:
The demo > build.gradle and library > build.gradle are per module files. The other one is the project file.
So to get rid of the error change the buildToolsVersion (can be done with a quickfix alt+enter) to "19.1" in both per module build.gradle files.
And then "Try again" to resync the gradle project.
Last error is: Error:(18, 0) Gradle DSL method not found: 'runProguard()'
In v.1 of the android gradle plugin they have changed runProguard to minifyEnabled, so just change one to the other in the libary > build.gradle, resync, and the project should launch.
You can directly import the project via GitHub/Git/Mercurial/SVN from Quick Start.
Otherwise, go to File > New > Project from Version Control and then choose the version control you are using.
In Your Case I would say you choose "Use default gradle wrapper" and studio automatically solve your gradle issues.
Using Eclipse IDE
Following the: https://developers.google.com/games/services/android/quickstart
Using the copy of google-play-services_lib (as recommended) and imported as Eclipse project.
Editing the game manifest with:
Adding our APP ID to res/values/strings.xml
Linked google-play-services_lib with our game project and set references in Order and Export tabs in the project settings
In accordance with https://developers.google.com/games/services/android/init using the project BaseGameUtils, from which our activity cannot inherit, because there’s another class already.
So, we moved to the second method without inheriting (see Using GameHelper without BaseGameActivity). We linked google-play-services_lib for BaseGameUtils and set the Library (compilation went down OK).
Linking added to our project to be able to use GameHelper as well as google-play-services_lib.
At this moment SDK from Facebook started causing trouble, so we had to add android-support-v4.jar (used by BaseGameUtils as well) and error during compilation occurs:
Found 2 versions of android-support-v4.jar in the dependency list,
but not all the versions are identical (check is based on SHA-1 only at this time).
All versions of the libraries must be the same at this time.
Versions found are:
Path: /Users/travis/Work/Craneballs/Mafia_android/facebook-android-sdk/facebook/libs/android-support-v4.jar
Path: /Users/travis/Work/Craneballs/Mafia_android/BaseGameUtils/libs/android-support-v4.jar
the project can be launched, but crashes on GoogleHelper = new GameHelper(this, GameHelper.CLIENT_ALL)
with the error message: java.lang.NoClassDefFoundError: com.google.example.games.basegameutils.GameHelper
I’ve spent many painful hours on this and am at my wits end. Any ideas?
I was having the same problem.
Here's the solution that fixed it for me:
I had the same issue, I did the following to fix the problem.
Go to "Properties" of the project.
Select "Java Build Path"
Select "Order and Export" Tab
You should see the selected project's "src" and "gen" paths and dependencies here.
The order how they listed were first "src" and then "gen" path
I switch them, so that "gen" folder is build before the "src"
gen - automated code in project (from dependencies and references)
src - source code in project
There was no need to restart the Eclipse. It just started working.
Honestly I have never tried "Android Tools > Fix Project Properties", sometimes it might be doing the same thing. I do not know, I just did above after seen the error message, thinking something is wrong with the build paths.
Resources that might help...
NoClassDefFoundError for code in an Java library on Android
Android app crashes after SDK-tools update version (NoClassDefFound, tool version 22)
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.
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.
I have come across a strange error. I have an Android project that uses external libraries, in particular:
android-support-v4.jar (for Fragment support in Android 1.6)
GoogleAdMobAdsSdk-4.3.1.jar (for ads)
The project ran fine until I updated some aspects of the plugin (can't recall the specifics as I did not pay too much attention to it) and after that, whenever I try to use any class from the above .jar files (or any of its subclasses, even ones defined by me), I would get a java.lang.NoClassDefFoundError. I could not find the answer after much searching, so I am really stumped.
I believe this problem is related to how my IDE is set up and it has little to do with actual code, so I will not post any unless if it's absolutely necessary.
You need to read this - Dealing with dependencies in Android projects.
This link is also useful - ClassDefNotFoundError with ADT 17
Basically, create a folder called libs and place all of your jar files inside. The recent update will automatically take care of the rest for you. You don't need to edit your path anymore.
Android does not support Java1.7 up to now. Jars built with compliance level 1.7 cannot be used in Android Applications. Rebuild your Java project with compliance level 5.0 or 6.0 before exporting the jar file.
I found this post via google and answers above didn't solve my problem. Hope what I say will be helpful to others.
If you see NoClassDefFoundError after upgrading to ADT 22, try this in Eclipse:
Go to Project Properties → Java Build Path → Order and Export tab.
Check the Android Private Libraries option.
Also a warning to others who have updated to r17 with many dependencies. I had a another referenced project on my build path and it still did not work after following ALL the directions on this r17 issue on the internet.
Found out after an hour that my referenced project used an older version of an external Jar than my main project did. When trying to compile the main project, Eclipse would give up due to this jar version difference and I never noticed the warning message in Console.
Solution was to copy the newer version external jar file to the referenced project's libs directory.
Wow - such a productivity killer.....
I ran into this error today too, because of updating to the Android SDK, r17. What the links that #aneal pointed out do not discuss is how to handle external runtime libraries (such as those imported under their own heading - not an imported user library).
The easiest way to solve this problem is to change the build order in the build path. Simply right click on your project and select Properties. From here, select Java Build Path. At the top of the display, choose the tab order and export and move GoogleAdMobAdsSdk-4.3.1.jar above Android X (replacing x with the version you are using). Next, clean your project and run it. You should be good to go!
The way I solved it was by : Right clicking on the project and selecting build path. Select configure build path in the selections that appear. After that see if your libraries are there in the libraries folder and then select the order and export tab and over there select all your jar files. Then select ok and run your project.
If you're using Eclipse with Maven IDE (m2e) go to "Java Build Path" then "Order and Export" and finally check the item "Maven Dependencies" and pull it down to the BOTTOM of the list. You should do the same with project references in the same workspace.
Every time I setup the project in a new computer that happens.