I have a android project with a runtime directory, and there is a jar file in this directory. This project can be built in eclipse. However, if I put the jar file in some other place, say, libs directory. This project would fail to build. In addition, even if I place the jar file in the runtime directory, this project cannot be built in Intellij. When the project fails to build, the error logs looks like the following.
Android Dex: [GameDemo] EXCEPTION FROM SIMULATION:
..... bad range 5..6; actual size 5
at bytecode offset 0000005
while processing ()V
So here are my questions:
Given a project in Eclipse, why project can be built when the jar file is in runtime library, but not when it's in libs directory.
Even though the jar is in runtime directory, why this project cannot be built in Itellij. What's the difference in build process of the two ide in term of android project.
Thanks!
I believe you are having this issue because you are trying to integrate CMCC's mobile SDK. It's a piece of garbage but that's another topic. For your purpose, just setting the library as "Provided" instead of "Compile" in the module settings of your IntelliJ project will get you past the compile stage. the SDK's probably loading it on the fly but not sure why that's necessary. Also be careful how you add the dynamic lib they provided. Make sure you do a plain copy instead of through the android NDK module dependency crap.
Seems they wanna avoid their sdk to be easily decompiled and byte hacked.
So they provided a dev time lib written in java that has interface feature only and implemented the real logic/type/class in a native lib.
Related
For a project I completed a game in Java on Eclipse using LibGDX. I now need to turn in the source code to my professor. When I export the project and try opening it on a new computer, about a dozen libraries are missing.
I would like to export my entire project so that when the project is opened in eclipse, it will still compile. Is there any way to do this? I know that runnable jars come with the .jar files of the dependencies and no source code, but I need both.
Thanks in advance
Libgdx required number of dependent jars so it's hard to manually add all jars into project.
Make your project gradle based so that When you import your project through gradle into another System then gradle do most of your task* for you.
*gradle try to find dependent jars in file system if already exist then link with your project if not then it download from given repository and link them in your project. Make sure your system is connected with internet when you build your project.
I highly encourage to use Android Studio or IntelliJIDEA.
On window, by default all jars are stored inside
C:\Users\User_name\.gradle\caches\modules-2\files-2.1
In Mac OSX
/Users/User_name/.gradle/caches/modules-2/files-2.1
When you want to deploy or packaging for the desktop run this command on your IDE terminal.
gradlew desktop:dist
You can use maven or gradle to build your project, take a look of one of the tool and it's won't take you too much time. these tool could help you define your own way for build
A much easier way you could use "fat jar". this is an old tool for build a jar with all lib you need and could be run in any place.
I have a .jar library and used 7-zip to extract the files and edit the .java source code inside.
I need to be able to build this to update the .class files before I turn it back into a .jar.
The library won't build as it's missing dependencies, but I don't know how to add these.
The library's using JNI, and LibGDX, and as an amateur, I am out of my depth on this problem that I am stuck on.
The original .jar file is in the link below
https://github.com/finnstr/gdx-liquidfun-extension/blob/master/libs/gdx-liquidfun.jar
Download following 2 JARs and add them to the build path of your Eclipse project. If you're not using Eclipse then add them to classpath, however it will be a lot easier to do with Eclipse.
http://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx/1.5.2
http://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx-jnigen/1.5.2
I have included older version from 2014, as the source code that in the git for liquidfun is using some older version of classes which are not available in new version of above JARs.
Eclipse has an option to export project as a JAR file. Use that and you're done.
If you're using plain Java then you'll have to compile all directories one by one (Java: How can I compile an entire directory structure of code ?)
I have problem with new gdx-setup.jar. Now when You are trying to generate new project after choosing everything the gdx will generate whole project from You, it will even configure Build Path - there is where my problems starts.
So gdx is creating a path to its libraries something like 'C:/users/user/28193721946210/.gradle/ ...' and so on.
Now - I want to work on this project on another machine - I am sharing project between computers with bitbucket. I was trying to unpin these dependencies from build path and just import my own libraries instead but I can't do much in here. Gradle have only power here, but in fact - there isn't any path in gradle.build or something - I can't make him to use my won dependencies instead of the generated ones.
it will even configure Build Path ... creating a path to its libraries something like 'C:/users/user/28193721946210/.gradle/
This is correct, as Eclipse or any other IDE needs to know where the files are that it needs, on the actual, local machine.
However, these kind of platform specific settings are not static. They also should not be checked into any shared source versioning system.
If you are using git, the gdx-setup will conveniently generate a handy .gitignore file that will set all eclipse specific config files on ignore, for example .project or .classpath files.
LibGDX projects these days are built via gradle. That's why your IDE needs a gradle plugin to be able to read gradle configuration files, most importantly build.gradle, which defines the dependencies for your projects.
When importing those projects into your IDE, the IDE will parse the config files, understand which dependencies it needs, download them to your local machine and then setup a local build-path to those dependencies. However this IDE configuration can change when you trigger an update. In eclipse you do this for example via a rightclick on the project --> Gradle --> Refresh Dependencies.
Furthermore, it will setup the correct local paths on any machine you want to develop your game on.
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...
I have a project that shares models with my android project. I have a separate eclipse project just for models and other shared code. I add this to my play project as a dependency in eclipse.
In eclipse, play compiles and starts without problem. However, I went to deploy to GAE and found that the compilation stage of play's packaging fails because it can't find the models.
I suspect I could hack the ant build files, but that seems brittle.
Is there a standard way to add extra directories to the play compilation source tree or the classpath?
Make a jar-file with your classes and put it in /lib. That's where I put my libraries.
Files in the application /lib folder is automatically added to the class path by Play Framework. See Classpath settings
From Anatomy: "The app directory contains all executable artifacts: Java and Scala source code, templates and compiled assets’ sources" ... and further: "You can of course add your own packages, for example an app/utils package"
You can copy java source files to make a hierarchy of packages under /app, e.g.:
/app/sharedcode/project2/models/domain1 and import that in WhateverController.scala as:
import sharedcode.project2.models.domain1._