I'm using libGDX for my game which shares some code with another project. I put this code in a .jar library which I have added in the root build.gradle.
Everything works fine on desktop, but when I launch the game on Android it crashes with a ClassNotFound exception. It can't find a class of my the library.
Can anyone help me out? I have no idea what is causing the problem.
Edit: changes to build.gradle:
project(":core") {
apply plugin: "java"
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile fileTree(dir: '../libs', include: '*.jar')
}
}
You need to add the same fileTree dependency directly in the android module because the Android Gradle plugin currently can't handle transitive flat file dependencies.
project(":core") {
...
compile fileTree(dir: '../libs', include: '*.jar')
...
}
// And also
project(":android") {
...
compile fileTree(dir: '../libs', include: '*.jar')
...
}
Source.
Related
I have 3 modules: annotations, annotation_processor and app.
annotations/build.gradle
apply plugin: 'java-library'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
annotation_processor/build.gradle
apply plugin: 'java-library'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
api project(":annotations")
api "com.squareup:javapoet:1.11.1"
}
repositories {
mavenCentral()
}
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
task deleteJar(type: Delete) {
delete 'libs/annotations.jar'
}
task createJar(type: Copy) {
from('build/intermediates/bundles/release/')
into('libs/')
include('classes.jar')
rename('classes.jar', 'annotations.jar')
}
createJar.dependsOn(deleteJar, build)
and app/build.gradle
dependencies {
...
implementation files('libs/annotation_processor.jar')
annotationProcessor files('libs/annotation_processor.jar')
...
}
When I run the project I get the following error.
error: package com.annotations does not exist
If I include annotations as a project the project I can skip this error but then I get.
Caused by: java.lang.NoClassDefFoundError: com/annotations/ProviderApi
at com.annotation_processor.ProviderAnnotationProcessor.getSupportedAnnotationTypes(ProviderAnnotationProcessor.java:45)
at org.gradle.api.internal.tasks.compile.processing.DelegatingProcessor.getSupportedAnnotationTypes(DelegatingProcessor.java:47)
at org.gradle.api.internal.tasks.compile.processing.NonIncrementalProcessor.getSupportedAnnotationTypes(NonIncrementalProcessor.java:33)
at org.gradle.api.internal.tasks.compile.processing.DelegatingProcessor.getSupportedAnnotationTypes(DelegatingProcessor.java:47)
at org.gradle.api.internal.tasks.compile.processing.TimeTrackingProcessor.access$101(TimeTrackingProcessor.java:37)
at org.gradle.api.internal.tasks.compile.processing.TimeTrackingProcessor$2.create(TimeTrackingProcessor.java:68)
at org.gradle.api.internal.tasks.compile.processing.TimeTrackingProcessor$2.create(TimeTrackingProcessor.java:65)
at org.gradle.api.internal.tasks.compile.processing.TimeTrackingProcessor.track(TimeTrackingProcessor.java:117)
at org.gradle.api.internal.tasks.compile.processing.TimeTrackingProcessor.getSupportedAnnotationTypes(TimeTrackingProcessor.java:65)
I can't access any of the dependencies (Java Poet and annotation module) from annotation_processor even though I have replaced implementation with api. Which should've expose the dependencies, but haven't.
I need the dependencies of the .jar file in the app module.
I'm new to Java Library and it may be I'm making a basic mistake, but can't seem to figure out, I've been at it for more than a day now.
You have to create a multi module gradle project.
I provide a small snippet of a multi module project.
project(':module1') {
dependencies {
compile project(':module-service-api')
compile 'org.apache.commons:commons-lang3:3.3.2'
compile 'log4j:log4j:1.2.17'
}
}
//module-app depends on module-service-impl
project(':module2') {
dependencies {
compile project(':module1')
}
For more details about multi module project, refer to the file build.gradle in the following project.
https://github.com/debjava/gradle-multi-module-project-1
If you want to create a fat jar or one jar, you have to include Gradle shadow plugin so that you can distribute the jar file along with other dependencies.
Refer below the link.
https://plugins.gradle.org/plugin/com.github.johnrengelman.shadow
I want to make an expansion panel in my Android app but I tried many libraries and all of them can't sync in my Android Studio.
This is my build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.github.florent37:expansionpanel:1.1.1'
}
apply plugin: 'com.google.gms.google-services'
and this is what happens after sync:
Error:Failed to resolve: com.android.support:appcompat-v7:26.1.0
Install Repository and sync projectOpen FileShow in Project Structure dialog
You should change
compile 'com.android.support:appcompat-v7:25.1.1'
to
compile 'com.android.support:appcompat-v7:27.1.1'
which is the latest available version found here
https://developer.android.com/topic/libraries/support-library/packages
Add this to your project level gradle inside allprojects -> repositories
Add maven { url "https://maven.google.com" }
okay.. I'm trying to create a splash screen for my mobile game. im using lib gdx library to create my game. i have a problem with importing the universal tween engine for my sprite splash. what should I do.
I've downloaded the universal tween engine and extracted it in the "libs" folder in the ios, android, core, and root of my project.. and i copied and paste these lines for each dependencies:
project(":core") {
fileTree(dir: 'D:/game/core/libs', include: 'tween-engine-api.jar')
compile fileTree(dir: 'D:/game/core/libs', include: 'tween-engine-api->sources.jar')
project(":desktop") {
compile fileTree(dir: 'D:/game/desktop/libs', include: 'tween-engine-api.jar')
compile fileTree(dir: 'D:/game/desktop/libs', include: 'tween-engine-api->sources.jar')
project(":ios") {
compile fileTree(dir: 'D:/game/ios/libs', include: 'tween-engine-api.jar')
compile fileTree(dir: 'D:/game/ios/libs', include: 'tween-engine-api->sources.jar')
project(":android") {
compile fileTree(dir: 'D:/game/android/libs', include: 'tween-engine-api.jar')
compile fileTree(dir: 'D:/game/android/libs', include: 'tween-engine-api->sources.jar')
the code in my Spite accessor class :
package com.game.test;
import aurelienribon.tweenengine.TweenAccessor;
public class SpriteAccessor implements TweenAccessor{
}
the error:
Error:(3, 33) java: package aurelienribon.tweenengine does not exist
Error:(5, 40) java: cannot find symbol symbol: class TweenAccessor
P.S.
Im following a video tutorial by dermetfan and I also put in th terminal these lines:
gradlew --refresh-dependencies
LibGdx uses gradle for dependency management.
You can inject dependency from repository.
add these lines in your core module of root build.gradle file.
repositories {
maven { url "https://jitpack.io" }
}
compile 'com.github.arcnor:universal-tween-engine:6.3.4'
compile 'com.github.arcnor:universal-tween-engine:6.3.4:sources'
My goal is to distribute an .aar file that can be used by other developers in their projects. The problem I find is when i try integrate my .aar into other project, is i need specify all of the dependencies in their build.gradle file that I have already included in my .aar build.gradle.
My question it if possible only include my library as a dependency and somehow the libraries that my library depends on will get included in the other project.
For example, my library defines the following dependencies in its build.gradle file:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.altbeacon:android-beacon-library:2.3.5'
compile 'commons-codec:commons-codec:1.10'
}
I wrote a test app that uses my library and add like module in Android Studio interface
dependencies {
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:7.5.0'
compile project(':myLibrary')
}
However, this does not work. I get java.lang.VerifyErrors at runtime. What ends up working is to include this in the app's build.gradle file:
dependencies {
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:7.5.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.altbeacon:android-beacon-library:2.3.5'
compile 'commons-codec:commons-codec:1.10'
compile project(':myLibrary')
}
Why do I need to include dependencies in both the .aar and the final application? What am I not understanding about how dependencies work? Why isn't the final application able to grab the .aar's dependencies from maven or jCenter at build time?
Maybe I'm not setting up my dependencies properly, but Gradle insists on expanding all of my dependencies into tmp/expandedArchives which effectively makes Gradle useless. I need various JARs from WebSphere, and with Ant I would just add them to javac's classpath.
What am I doing wrong? Is there some sort of flag I can provide to my compile dependencies to just add them to the classpath?
apply plugin: 'java'
apply plugin: 'war'
dependencies {
compile fileTree(dir: '../MyEarName/lib', include: '*.jar')
compile fileTree(dir: wasHome + '/lib', include: '*.jar')
compile fileTree(dir: wasHome + '/plugins', include: '*.jar')
compile fileTree(dir: wasHome + '/runtimes', include: '*.jar')
compile fileTree(dir: wasHome + '/java/jre/lib', include: '*.jar')
}
war {
webAppDirName = 'WebContent'
}
sourceCompatibility = 1.6
targetCompatibility = 1.6
sourceSets {
main {
java {
srcDir 'src'
}
}
}
compileJava {
options.fork = true
options.incremental = true
}
Thank you!
Turns out this was because options.incremental = true. Removing that fixed the problem.
Search for hours, finally post to SO, figure out the answer shortly after...