ObjectBox DuplicateFileException - java

We are migrating from ObjectBox 0.9.15 to 1.3.4.
After updating classes (removing #Relation, etc) we added dependency for ObjectBox Browser and get following error that appears on build:
Error:Execution failed for task
':app:transformNativeLibsWithMergeJniLibsForDevelopmentDebug'.
com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files
copied in APK lib/armeabi-v7a/libobjectbox.so
File1:
/Users/gaket/.android/build-cache/40bfb66d64a6d186c399e949921eb119d45150b8/output/jni
File2:
/Users/gaket/.android/build-cache/b30b0ce17a00dfed1ecea8969f4b6fa9a5fe7351/output/jni
Our application consists of two modules: Application type and Library type. ObjectBox plugin and dependencies are used and declared only in Application module. If we change dependency to one without browser, everything works smoothly:
// This works well:
// debugCompile "io.objectbox:objectbox-android-objectbrowser:$objectboxVersion"
debugCompile "io.objectbox:objectbox-android:$objectboxVersion"
releaseCompile "io.objectbox:objectbox-android:$objectboxVersion"
Proguard is turned off, multidex enabled.
Do you have any idea what could be the problem?
Applying plugins:
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
maven { url "http://objectbox.net/beta-repo/" }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.25.1'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0'
classpath 'com.google.gms:google-services:3.1.2'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2'
classpath 'io.objectbox:objectbox-gradle-plugin:1.3.4'
classpath 'me.tatarka:gradle-retrolambda:3.7.0'
classpath 'com.google.firebase:firebase-plugins:1.1.1'
classpath 'com.google.gms:google-services:3.1.2'
}
}
apply plugin: 'com.android.application'
apply plugin: 'com.getkeepsafe.dexcount'
apply plugin: 'io.fabric'
apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'project-report'
apply plugin: 'io.objectbox'
// There are some oddities when retrolambda isn't the last plugin so try to keep it as the last applied plugin
apply plugin: 'me.tatarka.retrolambda'
// Other configs
// Finally
apply from: 'dependencies.gradle'
apply plugin: 'com.google.gms.google-services'
Dependencies of the Application module:
ext {
butterknifeVersion = '8.8.1'
conductorVersion = '2.1.3'
daggerVersion = '2.11'
exoPlayerVersion = 'r2.5.1'
facebookVersion = '4.24.0'
firebaseVersion = '11.8.0'
glideVersion = '4.0.0'
leakCanaryVersion = '1.5.4'
logbackVersion = '1.1.1-6'
okhttpVersion = '3.8.1'
retrofitVersion = '2.3.0'
supportVersion = '27.0.2'
objectboxVersion = '1.3.4'
dependencies {
compile project(':vyng-core')
// UI Libraries
compile 'com.beloo.widget:ChipsLayoutManager:0.3.7#aar'
compile 'com.muddzdev:styleabletoast:1.0.9'
compile "com.github.jarrodholliday:material-about-library:1.8.4"
compile('com.vdurmont:emoji-java:3.2.0') {
exclude group: 'org.json', module: 'json'
}
compile('eu.davidea:flexible-adapter:5.0.0-rc2') {
exclude group: 'com.android.support', module: 'design'
}
//noinspection GradleCompatible
compile "com.android.support.constraint:constraint-layout:1.1.0-beta4"
// Rx Libraries
compile 'io.reactivex.rxjava2:rxjava:2.1.6'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.4#aar'
compile 'oxim.digital:rx2anim:0.9.1'
compile 'com.jakewharton.rxbinding2:rxbinding:2.0.0'
// Fabric Libraries
compile('com.crashlytics.sdk.android:crashlytics:2.6.8#aar') {
transitive = true
}
//DB libraries
debugCompile "io.objectbox:objectbox-android-objectbrowser:$objectboxVersion"
releaseCompile "io.objectbox:objectbox-android:$objectboxVersion"
// Logger
compile 'com.jakewharton.timber:timber:4.6.0'
compile 'org.slf4j:slf4j-api:1.7.25'
compile "com.github.tony19:logback-android-core:$logbackVersion"
compile "com.github.tony19:logback-android-classic:$logbackVersion"
// Util Libraries
compile 'com.google.code.gson:gson:2.8.2'
compile 'com.googlecode.libphonenumber:libphonenumber:8.8.1'
compile "com.facebook.android:facebook-android-sdk:$facebookVersion"
compile 'com.writingminds:FFmpegAndroid:0.3.2'
compile 'com.google.guava:guava:23.0-android'
// Image Libraries
compile "com.github.bumptech.glide:glide:$glideVersion"
annotationProcessor "com.github.bumptech.glide:compiler:$glideVersion"
compile "jp.wasabeef:glide-transformations:3.0.1"
//compile 'jp.wasabeef:blurry:2.1.1'
// Support Libraries
compile "com.android.support:appcompat-v7:$supportVersion"
compile "com.android.support:design:$supportVersion"
compile "com.android.support:support-annotations:$supportVersion"
// Firebase Libraries
compile "com.google.firebase:firebase-core:$firebaseVersion"
compile "com.google.firebase:firebase-auth:$firebaseVersion"
compile "com.google.firebase:firebase-messaging:$firebaseVersion"
compile "com.google.firebase:firebase-invites:$firebaseVersion"
// Conductor Libraries
compile "com.bluelinelabs:conductor:2.1.4"
// Dependency Injection
compile "com.google.dagger:dagger:$daggerVersion"
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
provided "javax.annotation:jsr250-api:1.0"
annotationProcessor "com.jakewharton:butterknife-compiler:$butterknifeVersion"
//auth
compile "com.facebook.android:account-kit-sdk:$facebookVersion"
// Video Libraries
compile "com.google.android.exoplayer:exoplayer-ui:$exoPlayerVersion"
compile "com.google.android.exoplayer:exoplayer-core:$exoPlayerVersion"
compile "com.google.android.exoplayer:exoplayer-dash:$exoPlayerVersion"
compile "com.yqritc:android-scalablevideoview:1.0.4"
compile('com.github.jarrodholliday:videocache:2.7.1') {
exclude module: 'slf4j-android'
exclude group: 'com.google.android', module: 'android'
}
// Networking Libraries
compile "com.squareup.retrofit2:retrofit:$retrofitVersion"
compile "com.squareup.retrofit2:converter-gson:$retrofitVersion"
compile "com.squareup.retrofit2:adapter-rxjava2:$retrofitVersion"
compile "com.squareup.okhttp3:logging-interceptor:$okhttpVersion"
compile "com.squareup.okhttp3:okhttp:$okhttpVersion"
// Debug/Testing
debugCompile "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"
releaseCompile "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion"
testCompile "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion"
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:2.10.0"
androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.0') {
exclude module: 'support-annotations'
exclude group: 'com.google.code.findbugs'
}
}
}

I decided to leave previous common answer because it can help other people with other libraries.
Specifically for ObjectBox, the reason is that we should put dependencies before applying the plugin, I missed this point in documentation (in "Setup" block):
// ObjectBox browser dependencies must be set before applying ObjectBox plugin so it does not add objectbox-android
// (would result in two conflicting versions, e.g. "Duplicate files copied in APK lib/armeabi-v7a/libobjectbox.so").
dependencies {
debugCompile "io.objectbox:objectbox-android-objectbrowser:$objectboxVersion"
releaseCompile "io.objectbox:objectbox-android:$objectboxVersion"
}

Adding packagingOptions (details are in docs) inside android part of gradle.build helped. However, if someone knows cleaner and not so shallow solution, I will be glad to see it.
android {
// some stuff
packagingOptions {
pickFirst 'lib/armeabi-v7a/libobjectbox.so'
pickFirst 'lib/arm64-v8a/libobjectbox.so'
pickFirst 'lib/x86_64/libobjectbox.so'
pickFirst 'lib/x86/libobjectbox.so'
}
}

Related

NoClassDefFoundError on Spring application

Full error is in this image as I am running on virtual machine in cloud which is access via video feed so I cannot copy and paste.This is a fresh install of ubuntu where I have only installed JDK and nothing else so unaware if other setup needs to be done
https://imgur.com/a/egJ3d
It is a spring boot application.
My build.gradle
group 'com.haughon.daniel'
version '1.0-SNAPSHOT'
buildscript {
repositories{
mavenCentral()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE'
}
}
// Apply the Spring Boot plugin
apply plugin: 'spring-boot'
// Apply the Java plugin (expects src/main/java to be source folder)
apply plugin: 'java'
apply plugin: 'idea'
// Specify the location where our dependencies will be found
repositories {
mavenCentral()
}
jar {
manifest {
attributes 'Main-Class': 'haughton.dvdstore.Application'
attributes 'addClasspath': 'true'
}
}
// Specify dependencies
dependencies {
compile 'org.hashids:hashids:1.0.1'
compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
compile 'org.springframework:spring-orm:4.3.7.RELEASE'
compile 'org.hibernate:hibernate-core:5.2.9.Final'
compile 'org.hibernate:hibernate-entitymanager:5.0.6.Final'
compile 'org.apache.tomcat:tomcat-dbcp:8.0.30'
compile 'org.springframework.boot:spring-boot-starter-security'
compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity4')
//compile 'org.thymeleaf.extras:thymeleaf-extras-springsecurity:3.0.2.RELEASE'
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.11.1.RELEASE'
// https://mvnrepository.com/artifact/com.google.code.gson/gson
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.8'
runtime 'com.h2database:h2'
runtime 'javax.transaction:jta:1.1'
runtime 'org.aspectj:aspectjweaver:1.8.7'
testCompile 'org.springframework.boot:spring-boot-starter-test'
}
This is because your dependencies are not included in one jar file.
use ./gradlew clean build
please see this post:
java.lang.NoClassDefFoundError: when trying to run jar

Failed to resolve: com.android.support:support-fragment:26.1.0 [duplicate]

This question already has answers here:
Failed to resolve: com.android.support:cardview-v7:26.0.0 android
(26 answers)
Closed 5 years ago.
Mark my question by This Question Link but the question is not similar to this question.The reason is - "com.android.support:support-fragment:26.1.0" dependency not added to my project. The question has different reason and different error. Also the answer of Question Link is not work for this problem.
I am using Android Studio 2.3.3 and Android Studio 3.0 BETA 6 side by side in my pc. In my project I get the error as below image -
I am using dependencies-
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:design:26.+'
compile 'com.android.volley:volley:1.0.0'
compile 'com.android.support:recyclerview-v7:26.+'
compile 'com.android.support:cardview-v7:26.+'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.facebook.android:account-kit-sdk:4.+'
compile 'com.karumi:dexter:4.1.1'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.slider:library:1.1.5#aar'
compile 'fr.avianey.com.viewpagerindicator:library:2.4.1.1#aar'
compile 'com.wdullaer:materialdatetimepicker:2.3.0'
compile 'com.jakewharton:butterknife:8.7.0'
compile 'com.flaviofaria:kenburnsview:1.0.7'
compile 'com.google.firebase:firebase-core:11.2.0'
compile 'com.google.firebase:firebase-database:11.2.0'
compile 'com.google.android.gms:play-services:11.2.0'
compile 'com.android.support:multidex:1.0.1'
testCompile 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0'
}
apply plugin: 'com.google.gms.google-services'
and use -
compileSdkVersion 26
buildToolsVersion "26.0.0"
in the gradle file I use this code -
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.1.0'
classpath 'com.google.firebase:firebase-plugins:1.0.4'
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I am stuck to find this problem solution.
You have to add maven { url 'https://maven.google.com' } in repositories section.
buildscript {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.0.0'
}
}

Duplicate entry in build.gradle while implementing Google + login

I am trying to integrate Google+ signup/login in a legacy (Eclipse) project imported in Android Studio following this tutorial. I am stuck while importing the dependencies in the build.gradle files.
The error says:
Error:Execution failed for task ':Study Story:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/print/PrintHelperKitkat$1.class
I am unable to debug the reason for such an error. The inner level build.gradle file has the following code:
import java.util.regex.Pattern
apply plugin: 'android'
apply plugin: 'com.github.triplet.play'
apply from: 'signingRelease.gradle'
apply plugin: 'signing'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
useLibrary 'org.apache.http.legacy'
defaultConfig {
minSdkVersion 15//lower than 14 doesn't support multidex
targetSdkVersion 21
// Enabling multidex support.
multiDexEnabled true
// For blurring images
renderscriptTargetApi 18
renderscriptSupportModeEnabled true
}
buildTypes{
release {
signingConfig signingConfigs.publishApkRelease
}
debug {
signingConfig signingConfigs.debug
}
}
play {
track = 'beta'
serviceAccountEmail = '436686241693-d4ts7q2davfmim1s20junur0qd9c7075#developer.gserviceaccount.com'
pk12File = file('keyfile.p12')
}
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
all*.exclude module: 'support-annotations'
}
repositories {
jcenter()
}
lintOptions {
abortOnError false
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
dependencies {
compile project(':Viewpage:viewpage-library')
compile project(':CountryPicker')
compile project(':numberpicker-library')
compile('com.facebook.android:facebook-android-sdk:4.13.0') {
exclude module: 'bolts-android'
exclude module: 'support-v4'
}
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
compile 'com.parse.bolts:bolts-android:1.+'
//compile 'com.parse:parse-android:1.11.0'
compile 'com.parse:parse-android:1.+'
//compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.google.android.gms:play-services-auth:9.0.0'
// glide is added to load the g+ profile image. Ignore if you want
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.google.android.gms:play-services-maps:9.0.0'
compile 'com.google.android.gms:play-services-analytics:9.0.0'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:design:22.+'
compile 'com.shamanland:fab:0.0.6'
//compile 'com.parse.bolts:bolts-android:1.1.+'
//compile fileTree(include: 'Parse-*.jar', dir: 'libs')
// compile fileTree(include: ['ParseFacebookUtilsV4-1.9.2.jar'], dir: 'libs')
compile fileTree(include: ['jsoup-1.7.3.jar'], dir: 'libs')
compile fileTree(include: ['ParseFacebookUtilsV4-1.10.3.jar'], dir: 'libs')
// compile fileTree(include: ['libGoogleAnalyticsServices.jar'], dir: 'libs')
//compile fileTree(dir: 'libs', include: ['android-support-multidex.jar'])
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:recyclerview-v7:22.2.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.traex.rippleeffect:library:1.3'
//SwipyRefreshLayout
compile 'com.github.orangegangsters:swipy:1.2.3#aar'
// compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile('com.android.support:cardview-v7:23.2.0') {
force = true
}
}
apply plugin: 'com.google.gms.google-services'
/*
This is not working yet.
*/
task('increaseVersionCode') << {
println('in increaseVersionCode')
def manifestFile = file("AndroidManifest.xml")
def pattern = Pattern.compile("versionCode=\"(\\d+)\"")
def manifestText = manifestFile.getText()
def matcher = pattern.matcher(manifestText)
matcher.find()
def versionCode = Integer.parseInt(matcher.group(1))
println('in increaseVersionCode ' + versionCode)
def manifestContent = matcher.replaceAll("versionCode=\"" + ++versionCode + "\"")
manifestFile.write(manifestContent)
}
task('incrementVersionName') << {
println('in incrementVeriosnName')
def manifestFile = file("AndroidManifest.xml")
def patternVersionNumber = Pattern.compile("versionName=\"(\\d+)\\.(\\d+)\\.(\\d+)\"")
def manifestText = manifestFile.getText()
def matcherVersionNumber = patternVersionNumber.matcher(manifestText)
matcherVersionNumber.find()
def majorVersion = Integer.parseInt(matcherVersionNumber.group(1))
def minorVersion = Integer.parseInt(matcherVersionNumber.group(2))
def buildVersion = Integer.parseInt(matcherVersionNumber.group(3))
def mNextVersionName = majorVersion + "." + minorVersion + "." + (buildVersion + 1)
println('Major Version ' + majorVersion)
println('Minor Version ' + minorVersion)
println('Build Version ' + buildVersion)
def manifestContent = matcherVersionNumber.replaceAll("versionName=\"" + mNextVersionName + "\"")
manifestFile.write(manifestContent)
}
//Activate this if you wish for Gradle to handle the build number increments.
/*
tasks.whenTaskAdded { task ->
println('When task is added: ' + task.name)
if (task.name == 'generateDebugBuildConfig') {
// println('IN IFSTATMENTWITH : ' + task.name)
task.dependsOn 'increaseVersionCode'
task.dependsOn 'incrementVersionName'
}
}*/
The project level (outer) build.gradle has the following code:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
//classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.github.triplet.gradle:play-publisher:1.1.4'
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.google.gms:google-services:3.0.0'
//classpath 'com.google.gms:google-services:1.4.0-beta3'
}
System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true'
}
allprojects {
repositories {
jcenter()
}
}
The folder structure looks like the below image:
Please point out the areas which I need to modify to fix the issue.
First, try to use the same API for compileSdkVersion, buildToolsVersion, targetSdkVersion, support:appcompat dependency, support:design dependency, support-recyclerview dependency, support:cardview dependency. In your app build.gradle, you need to stick to API 23.
Afaik, if you use:
useLibrary 'org.apache.http.legacy'
you don't need to add this dependencies:
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
because it doing the same with useLibrary (If my memory serve me well).
Then in your root build.gradle, you only need one build gradle tools:
//classpath 'com.android.tools.build:gradle:1.3.0' Use only one.
classpath 'com.android.tools.build:gradle:2.1.0'
And last, try to not using multidex for your application. Because an android app is faster without the multidex. Imho, By a glance of your build.gradle, you can go without multidex.
First of all make sure that your Android SDK is updated and use the same version of libraries that you are specifying as your Project's Dependency. Now to answer this error:
Error:Execution failed for task ':Study Story:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/print/PrintHelperKitkat$1.class
com.android.support:support-v4 and support-annotations package is imported multiple times with different version so you need to exclude them as below:
These are importing support-v4, support-annotations 23.0.0:
compile('com.google.android.gms:play-services-auth:9.0.0') {
exclude module: 'support-v4'
exclude module: 'support-annotations'
}
compile('com.google.android.gms:play-services-maps:9.0.0') {
exclude module: 'support-v4'
exclude module: 'support-annotations'
}
compile('com.google.android.gms:play-services-analytics:9.0.0') {
exclude module: 'support-v4'
exclude module: 'support-annotations'
}
This is importing support-v4, support-annotations 22.0.0.
// Just don't import this library as it's already imported in 'com.android.support:design'
compile('com.android.support:appcompat-v7:22.2.0') {
exclude module: 'support-v4'
exclude module: 'support-annotations'
}
This is importing support-v4 25.0.1. You should never specify dependencies having + in dependency: 'com.android.support:design:22.+' as that will always force your Project to use the latest libraries while building gradle that might lead to several build errors, some deprecated classes in your Project leaving it unstable. It is always recommended to update SDK on timely basis and specify the dependency version accordingly and verify that the code written is your Project is not missing any class in the latest library. In fact, design library is importing support-v4, appcompat-v7, support-annotations, recyclerview-v7 so you should avoid importing these libraries separately.
compile 'com.android.support:design:25.0.1'
It is again importing support-v4, support-annotations 22.2.1.
// Just don't import this library as it's already imported in 'com.android.support:design'
compile('com.android.support:recyclerview-v7:22.2.1') {
exclude module: 'support-v4'
exclude module: 'support-annotations'
}
This library is importing below modules having version 23.1.1:
compile('com.github.orangegangsters:swipy:1.2.3#aar') {
exclude module: 'support-v4'
exclude module: 'appcompat-v7'
exclude module: 'support-annotations'
}
It is importing support-annotations: 22.0.0
compile('com.github.traex.rippleeffect:library:1.3') {
exclude module: 'support-annotations'
}

kotlin project can't be build in gradle(can not find reference)

I have a java project that write in kotlin ,i use intelliJ IDEA to develop this project. I have trouble on the dependencies setting (multiple project). I already read lot of examples , but I can't find the workaround , here is my dependencies setting code, it can be build in java class correctly , but the kotlin class will get lot of error 'Unresolved reference' . Is that any wrong about my setting or gradle is not suitable with kotlin .
PS : when i only build core project , build process will successful , but build at test project will get the reference unresolved error
following is the code of build.gradle.
allprojects {
apply plugin: 'java'
apply plugin: 'kotlin'
group 'TestProject'
version '1.0'}
subprojects{
apply plugin: 'java'
apply plugin: 'kotlin'
def defaultEncoding = 'UTF-8'
compileJava.options.encoding = defaultEncoding
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
mavenLocal()}
dependencies {
// Kotlin
compile "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testCompile group: 'junit', name: 'junit', version: '4.11'
// JDOM
compile "org.jdom:jdom:$jdom_version"
// Jaxen
compile group: 'jaxen', name: 'jaxen', version: '1.1.6'
// JUnit
compile "junit:junit:$junit_version"
// Log4j2
compile "org.apache.logging.log4j:log4j-api:2.5"
compile "org.apache.logging.log4j:log4j-core:2.5"
// JOGL
String[] versions = "$jogl_version".split("\\.")
if (Integer.parseInt(versions[0]) >= 2 && Integer.parseInt(versions[1]) >= 2) {
compile "org.jogamp.gluegen:gluegen-rt:$jogl_version"
compile "org.jogamp.jogl:jogl-all:$jogl_version"
println "JOGL 2.2.0 later"
} else {
compile files("../libs/thirdparty/jogl/jogl-2/jar/jogl-all.jar")
compile files("../libs/thirdparty/jogl/jogl-2/jar/gluegen-rt.jar")
println "JOGL 2.1.5 before"}
runtime "org.jogamp.gluegen:gluegen-rt:$jogl_version:natives-linux-amd64"
runtime "org.jogamp.gluegen:gluegen-rt:$jogl_version:natives-linux-i586"
runtime "org.jogamp.gluegen:gluegen-rt:$jogl_version:natives-macosx-universal"
runtime "org.jogamp.gluegen:gluegen-rt:$jogl_version:natives-windows-amd64"
runtime "org.jogamp.gluegen:gluegen-rt:$jogl_version:natives-windows-i586"
runtime "org.jogamp.jogl:jogl-all:$jogl_version:natives-linux-amd64"
runtime "org.jogamp.jogl:jogl-all:$jogl_version:natives-linux-i586"
runtime "org.jogamp.jogl:jogl-all:$jogl_version:natives-macosx-universal"
runtime "org.jogamp.jogl:jogl-all:$jogl_version:natives-windows-amd64"
runtime "org.jogamp.jogl:jogl-all:$jogl_version:natives-windows-i586"
testCompile "junit:junit:$junit_version"
testCompile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
// Jython
compile 'org.python:jython-standalone:2.7.0'
// RxKotlin
compile 'io.reactivex:rxkotlin:0.55.0'
compile 'io.reactivex:rxswing:0.24.0'
// Mockito
compile 'org.mockito:mockito-all:1.9.5'
compile 'args4j:args4j:2.33'
compile 'org.json:json:20160212'
// Lombok
compile "org.projectlombok:lombok:$lombok_version"}
sourceSets.main.java.srcDirs = ['src']
sourceSets.main.kotlin.srcDirs = ['src']
sourceSets.main.resources.srcDirs = ['../res','src']
sourceSets.test.java.srcDirs = ['test']
sourceSets.test.kotlin.srcDirs = ['test']
sourceSets.test.resources.srcDirs = ['../res','src']
buildDir = 'build'}
buildscript {
// JOGL
ext.jogl_version = '2.1.0'
// Kotlin
ext.kotlin_version = '1.0.1'
// JUnit
ext.junit_version = '4.12'
// JDOM
ext.jdom_version = '1.1'
// Lombok
ext.lombok_version ='1.16.8'
repositories {
flatDir { dirs "lib" }
mavenLocal()
mavenCentral()}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"}}
dependencies {
buildDir = 'out'}
sourceCompatibility = 1.8
project(':mainproject') {
dependencies {
compile project(':core')
compile project(':movie')}}
project(':movie'){
dependencies{
compile project(':core')}}

how to add a library to the dependencies gradle of LIBGDX project

All is in the question , I've tried all the answers I found in SO and others sites but with no luck , this is what I've tried so far :
adding compile fileTree(dir: 'lib', include: '*.jar') to my build.gradle
adding compile files('lib/tween-engine-api-sources.jar') to build.gradle
the library I want to add is Tween engine .
build.gradle file :
buildscript {
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
}
}
allprojects {
apply plugin: "eclipse"
apply plugin: "idea"
version = '1.0'
ext {
appName = 'my-gdx-game'
gdxVersion = '1.5.4'
roboVMVersion = '1.0.0-SNAPSHOT'
box2DLightsVersion = '1.3'
ashleyVersion = '1.3.1'
aiVersion = '1.5.0'
}
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":desktop") {
apply plugin: "java"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"
}
}
project(":core") {
apply plugin: "java"
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-bullet:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
compile "com.badlogicgames.ashley:ashley:$ashleyVersion"
compile "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion"
compile fileTree(dir: 'lib', include: '*.jar')
}
}
tasks.eclipse.doLast {
delete ".project"
}
In the wiki article Dependency management with Gradle, you can find all the information you need. There's even an extra part about the Tween Engine.
Your approach should work, however, you need to update Eclipse via a Right-Click on your projects -> Gradle -> Refresh Dependencies.
For me it worked better though to install the dependencies in my local repository and then reference it from there, instead of referencing the lib folder. This is described here.

Categories