My project layout is
/ServerModule
/commonClasses
/AndroidClient
/needsToIncludeSomeCommonClasses
but as soon as i want to compile and build my AndroidClient IntelliJ adds the server libs to the compile classpath of my android project and I get a UNEXPECTED TOP-LEVEL EXCEPTION because of multiple classes that are present in android and normal java.
My question is how can i set up my project without duplicating the server code?
It seems to be a problem with the android-plugin.
It includes all the serverside libs in the build.
I found a solution.
I need to make a new module with common classes only and link this with the other two modules. Not very pretty but it works
I would ask IntelliJ support, http://www.jetbrains.com/support/idea/index.html they are usually very responsive or ask their Community Support Forum. http://www.jetbrains.com/devnet/
Related
So I took a Coursera course that had me work with external libraries. Two .jar files which most of the weekly projects depended upon.
I'm not entirely sure how eclipse compiles and runs the files, and how it links to these external libraries -- what is the proper way of organizing this? Do I put a copy of each .jar file in each project directory?
Is there another, cleaner way that I should be organizing this?
Thanks --
As a beginner programmer it is OK to put it in each project. But consider that this is ongoing work and at some time in future you want to upgrade to a new version of these external libraries. Then you would have to copy it everywhere.
Instead another option is to store them in one place and add it in classpath in each project. Now you have only one copy of it, which is always better.
Now, if and when you do get a new version then the file names might change, so you will still have to change the classpath of each project.
But I advise you to worry about these and other such problems later. For now, focus on programming related problems rather than configuration.
If you want to maintain your libraries professionally in a formal manor then you're better of using a build tool like Gradle of Maven.
I'd suggest you to use Gradle to maintain the project since it has a whole lot of useful build tools available to you to use. Eclipse has a Gradle plugin available which allows you to use Gradle projects with it. See link below.
To give you a idea of how Gradle is used professionally. Android uses it by default to maintain their projects now. So Android java projects uses the Gradle build tool to maintain its library sources, compilation processes and such.
The difference between a Gradle project and a normal java project is that a Gradle project has a list of pre-defined scripts available to you which fetches the libraries, compiles them and prepares them before exporting the final bundle (jar). So really all Gradle does in before hand is fetch the libraries and prepares the specified tools before compilation so you won't need to mess with them your self. It prepares your project directory and remotely maintains your libraries so if they're available from a repository then it'll make sure to prepare them appropriately in before hand and setup your projects directories.
So really the difference you'd physically notice is that instead of using the default Eclipse export button to create your bundle (jar) you'd instead use a button from the side menu which the Gradle plugin adds and also you'd cleanly list the libraries in a structured order in a file that gets added to your project root.
If you want to get a basic understanding of how it works and really want to start to proffesionally or formally structure your project then try to create a very basic android app in Android Studio. see link below
If this isn't what you want at all and don't want to take it to this advanced level yet then adding the library bundles into some kind of lib folder that's located in your project root is properly best practice.
If you wonder why? Well basically different projects might use different versions of the library which may add or remove support to them. So to keep the versions consistent and make sure to have the right version available to you, you have the direct source near the project it self.
Here's some useful link:
http://www.vogella.com/tutorials/EclipseGradle/article.html
http://developer.android.com/sdk/index.html
I recently asked a very similar question, but was unsure how to phrase it. Having received some feedback and researched some of the potential solutions, I'm now asking again with what I believe to be a better explanation of the issue.
My Android App uses my Library (parentLib), this library is built referencing methods from another library (childLib). Therefore, the App itself uses parentLib (A .jar library), which in turn uses childLib (Another .jar library).
The problem here is that when the app attempts to use anything that involves the nested library (childLib), it receives a NoClassDefFoundError, which crashes the App. I believe that this issue is due to the App being unable to resolve the nested dependency.
I can't really use Android library projects, as I need the source code to be as obfuscated and difficult to understand as possible. I have also tried creating these libraries using Android Studio, only to sadly receive no better outcome.
My options (I think) are:
Combine the Libraries
I could potentially combine childLib and parentLib into a single .jar library, seperating them out into different packages. This would be difficult though, as in practise there are around 6 nested libraries for my intended App.
Insist the Client use multiple libraries
Instead of saying to the client, "Here's one simple library (parentLib) for you to use", I could instead say, "Here's 7 different libraries for you to import (parentLib, childLib, etc.), otherwise nothing will work". Not exactly professional!
Other Options
I would welcome any other suggestions anybody has!
Thanks in advance.
The NoClassDefFoundError means that the the class was present during compilation, but not available in the classpath when trying to execute it.
So, you need to tell gradle to compile those libraries and package them inside the apk.
Copy all the library jars you need to the libs folder in the root of you project. Then, edit the gradle.build file and add the following:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
This will cause all the required libraries to be added to your apk. This way, the classes you need will be present in the classpath when you execute the code that needs them.
Resolved by moving to Android Studio (where such issues are not present).
I found some cool android libraries the other day and decided to try some. But I'm having trouble correctly importing the library.
This is the URL of the library : https://github.com/dmytrodanylyk/android-process-button
I first tried importing the library to eclipse (and move the files in java directory to src directory and set the project as library) and importing the sample to eclipse and set it to use the library project (Properties->Android->Libraries). But it didn't work. The layout files said it failed to instantiate [custom widget class].
The I tried importing the .jar file to libs directory (and update the java build path) but it didn't work either. It showed errors in the java files too.
I then tried copying all the java and layout files to the sample project directory and it worked. But I'm guessing that's not the way to work with 3rd party libraries.
I first thought it's some error with the library but all the other libraries I tried to import to my projects faced the same problem.
Can someone walk me through how to correctly import a 3rd party library to my android project?
The best option you can do is to use gradle as your dependency manager.
The library you have posted is using Gradle so you can link to this library in this way:
dependencies {
compile 'com.github.dmytrodanylyk.android-process-button:library:0.0.7'
}
And voilá! You have your library ready to use in your app :D
I'll let you a couple of useful links to use Gradle properly:
Mark Allison's tutorial about Gradle It will explain step by step how Gradle works (keep in mind that is using an outdated version of Android Gradle plugin, you have to adapt the version to the current one which is 0.10)
Official Developer Docs about Gradle In here you can find another step by step tutorial to configure and use Gradle (this one is more updated).
You can use Gradle directly in Android Studio (Intellij) if you don't mind to change your main editor.
If you want to stick around with Eclipse then this stackoverflow link may be helpful!
EDIT:
Oh! And if you want to search already Gradlized libraries you can navigate to Gradle Please!
I see the library uses gradle. So if you use gradle for dependency management or Android Studio (which uses gradle by default) importing will be a breeze. The installation instruction for gradle is even available at the github project site.
dependencies {
compile 'com.github.dmytrodanylyk.android-process-button:library:0.0.7'
}
I'm using ORMLite on our Android app, and I've previously set up an ormlite_config.txt as described in the documentation
http://ormlite.com/docs/table-config
I've now updated my classes, so I need to regenerate the file, but I can no longer get my DatabaseConfigUtil to run in Eclipse. I've set the Run Configuration as described in the documentation, choosing the local JRE and removing the Android bootstrap entry from the Classpath tab. But I just get a whole bunch of java.lang.NoClassDefFoundError for all the Android-derived classes in my project.
I've obviously changed something since I originally generated the ormlite_config.txt file, as I didn't have any problems before, but I can't see what I've done to break everything.
Can somebody tell me exactly what I should have in my Classpath / source tabs?
In the end the instructions in the documentation were all that was required, there was just a pair of bugs introduced in 4.43 that prevented it working as it should. These have now been fixed, and will presumably be in the next version. See https://groups.google.com/forum/?fromgroups=#!topic/ormlite-android/nBuQTVpCs0g
I ran into this exact problem and found out a solution myself.
I think the problem came from Google's ADT plugin. Since the plugin manages the Android libraries as private libraries, ORMLite Util cannot find the Android related classes in the project's build path.
The solution is to manually add the android.jar from your android sdk folder (in my case it's C:\android-sdk\platforms\android-18) into the build path as an external jar.
Hope it helps.
You have to remove the Android Lib from Bootrap Entries!
Do as follows:
Project > Properties > Run/Debug Settings
Select the class you want to compile and click edit
open tab "classpath" and remove Android Lib from Bootstrap Entries
I am creating a library for Android that others can include in their own project. So far I have been working on it as a normal Java project with JDK 1.6 setup as system library. This works just fine in Eclipse when I add the android.jar.
The issue comes when I try to my build script. I am running Gradle and doing a normal compile and test build cycle. My thoughts were that it does not matter if I compile it with a normal JDK, since this is not a standalone application. The benefits by creating a normal Java project is that Gradle does support this much better. My project also does not contain any UI at all. However, the problem is that of course android.jar and the JDK contains lots of the same classes and I think that this is what messes up my build script. Everything crashes when running the tests (the tests are in the same project under src/test/java).
My question is, how should I create this project that is meant to be included in Android projects as a third party library? Should I create it as an Android project in Eclipse even though I am only creating a library that does not use any of the UI features? Also, should the tests be in a separate project?
Thanks for all responses!
Have you looked at the Android plugin for Gradle? It incorporates the ProGuard tool to package only necessary classes into your Android APK file, so might address your scenario. Have a look here: https://github.com/jvoegele/gradle-android-plugin/wiki
I will start with the simple question, the one regarding the test project. My experience is that is is better to have a separate test project. I have done this with success in many Java ME project, where the problems are similar. The test project only need to import the source code, not the libraries. Then there should be no problems with duplicate classes.
The other question is a little more difficult. My intuition tells me that the core project should be an Android project.