When trying to create a gradle project in eclipse, the source folder, build.gradle and others are stored in a different folder called lib as a separate project.
How can I make all the folders be within the project folder like in a normal java project?
The problem is that the New Gradle Project dialog invokes the Gradle init task with the hard-coded argument --type java-library and that the project layout for Gradle versions higher than 6.6.1 has a lib folder besides the main project folder for a project of the type java-library (in contrast to in Gradle 6.6.1 or lower and in contrast to a project of the type application independent of the Gradle version).
In the future, in the New Gradle Project dialog, the type application should also be chooseable, to get a simple project structure like in the past. But this is not implemented yet:
Eclipse Buildship issue #1118: Add more project templates to New Gradle Project wizard
As a workaround do the following:
In the New Gradle Project dialog on the second or third page, check Override workspace settings and
choose as Specific Gradle version the version 6.6.1 and
for Java home a Java 11 JDK
In the build.gradle change id 'java-library' to id 'application'
In Project > Properties: Gradle choose a higher Gradle version
The last two steps are only required to use a Gradle version higher than 6.6.1.
When I create a Gradle project in Eclipse the result is a nested project with a -lib folder created automatically. Any ideas on why this is being created?
I tested this on Eclipse 2021-03 using the latest gradle version 7.0-rc-1 and reproduced your issue where a nested project with a lib subproject was created. I then made a new Eclipse project specifying Gradle version 6.6 to be used and the resulting project was not nested. I suggest trying Gradle 6.6 and seeing if you get the same behavior I got. This might fix your project.
Also try running the gradle init command from the command line and see what project structure you get there. I tested this on my PC where I have gradle 5.6 as the default version and got a non nested structure. You can of course always manually modify your gradle project in a few minutes to not be nested.
Recently, my Android project is being told that it does not use the Gradle build system. Also, for some reason, the only folder listed within my project is the java folder, which contains R, the buildconfig, and the auto-generated manifest used by the IDE, but it doesn't contain the actual app files, located in the "app" folder. The "app" folder exists, but is not listed in the app. Furthermore, I am unable to drag and drop the folder into the hierarchy listed in Android Studio. Also, there's a build.gradle that isn't listed.
The app built fine before, and the only change I can tell is that I have pushed a newer version to Github after importing the entire thing from Eclipse. It built fine with the gradle build system after importing from Eclipse. I have just tried to commit the build.gradle into the app, which was unversioned before. The problem is that the project still claims to not use the gradle build system.
im still quite new to gradle. I decided to transfer some code i oft use into an subproject. This subproject is a pure java project, so im using only the apply plugin: 'java' there.
I can build this project and in the build folder is see a jar which contains the compiled classes after the gradle assemble command was invoked.
What really bugs me at the moment is, how can i use the classes in my Android project using Android Studio ?
I tried to use the compile project command:
compile project(':PureJavaSubProject')
And it compiles the Project as expected. But Android Studio is not able to see the artifacts created by the Project ?
I read a bit in the Gradle Docs about Artifacts management but the Doc is not clear for me.
Anyone can point me how i need to declare or setup the gradle build to make it work ?
Are you including the subproject from your root project in your settings.gradle?
include 'PureJavaSubProject'
I can't verify from Android Studio I'm afraid. There is also more doc on multi project builds here:
http://www.gradle.org/docs/current/userguide/multi_project_builds.html
I had this same issue, and it turned out I had the directory structure for the Java subproject slightly wrong (I had copied it from another existing Eclipse project).
I had:
java-subproject/src/com/example/MyJavaClass.java
...when it should have been:
java-subproject/src/main/java/com/example/MyJavaClass.java
When I changed it to the correct structure, the main Android project then picked up the classes in the Java sub-project fine.
A fully working example of an Android Studio project with a pure Java sub-project can be see here on Github:
https://github.com/barbeau/JavaSubprojectDemo
I use eclipse for Google Android development.
I've created a library project ([x] Is Library in the Android-settings), which includes an external jar-file (Referenced Libraries). This library project are referenced in another Project (the actual project which will use the library project). This is done by add the project under the Android-settings.
the source compiles but if I want to execute it on the device, I get the NoClassDefFoundError for a class which is inside the jar-file which is included in the library project.
Edit: The jar-file ist added to the exported entries ([x] my.jar on the Order and Export-Tab from the library project)
Is there a clean way to get this working?
It has been clearly stated in offcial API here:
A library project can include a JAR library
You can develop a library project that itself includes a JAR library, however you need to manually edit the dependent application project's build path and add a path to the JAR file
The jar lib must be manually added to the dependent application project's build path, not only the library project build path itself.
Update from SDK r17:
This is automatically handled by ADT now, check out new feature for ADT 17.0.0 release here:
Added feature to automatically setup JAR dependencies. Any .jar files in the /libs folder are added to the build configuration (similar to how the Ant build system works). Also, .jar files needed by library projects are also automatically added to projects that depend on those library projects. (more info)
For those who followed the steps(even check the projects in "Order and Export") and still have the java.lang.ClassNotFoundException in the API 17, the final step is to check that your compiler does not run with Java 1.7. If is 1.7 then you should change it to 1.6 for all your projects. After that it will ask to rebuild all the projects and successfully ran on my phone :)
To change the java compile version in eclipse, this is located in: Project properties > Java Compiler > Compiler Compliance level: 1.6
Go to project properties -> build path-> libraies
If you see your jar files like this
snmp4j.jar - e:\software\jars
Its may your problem
Add libs folder in your project and copy jar file in that folder. Right click jar file and go build path -> add to build path. Then you can see your jar as
snmp4j.jar - project_name/libs
Its worked for me.
I had two projects using the same library: one working, the other one crashing with java.lang.NoClassDefFoundError.
After nothing else helped me, I looked into the file project.properties in the root directory of my project.
The working project had the android.library.reference line (the last line below), the crashing one did not:
# Project target.
target=android-17
android.library.reference.1=../my-library-project
I manually added the line and it started working!
(Yes, I did try both (project) properties -- java build path -- projects and (project) properties -- java build path -- order and exports -- nothing helped.)
PS By the way, "project properties" has also the "project references" tab. No idea if it would work.
I had a minor issue when I upgraded to ADT17 where my libs weren't being imported properly. Turns out this is because my librarys were being linked as dependancies from my lib folder not libs!
Seems librarys have to be in the libs folder from now
I had a similar problem and non of the solutions out here fixed it.
Short version: the JAR was compiled in Java 1.7 and could not be found by Dalvik.
We build an internal JAR that we share across backend and mobile clients with Maven. The problem ended up being that the JAR was compiled with Java 1.7. Androids dalvik only supports Java 1.5 and 1.6. This is why everything works fine in Eclipse as it's not compiled to dalvik at this point.
We even specified the target and source version in the Maven compiler plugin to compile with Java 1.6. This did not work because only JDK 1.7 was installed on the build machine. A small note at the bottom of the Maven page gave us the hint: Note: Merely setting the target option does not guarantee that your code actually runs on a JRE with the specified version.
To see if you have this problem as well, rename your *.jar file to *.zip unpack it, and look in the MANIFEST.MF file for the Build-Jdk: parameter to see what Java version actually compiled your JAR.
Another thing to pay attention to is library package names.
If you are using ADT21 and you happen to have libraries that have the same package name, there will be error during compile but it will still compile and run in Eclipse, giving you an APK that is missing some of the resource classes. Hence the crash when you run the app.
If you compile it with ANT then you can see the compile error that says two or more libraries use the same package name.
To fix this, rename your library project by using Android Tools -> Rename Application Package. Then everything will go back to normal.
It took me almost entire day to figure this out...