2

I have the two jar files downloaded and I have put them in the libs folder.

When I open the build.gradle project(":core") I can't find dependencies where I should put this code in:

compile fileTree(dir: '../libs', include: '*.jar')

It should look like this but I can't find it in the build.gradle:

project(":core") {
...

dependencies {
    ...
    compile fileTree(dir: '../libs', include: '*.jar')
}
}

This is the error i get in the Gradle Build Log:

Error:(8, 1) A problem occurred evaluating root project 'runningame'.

Could not find method compile() for arguments [directory '../libs'] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@72594296.

I have the jar files located here:

C:\Users\zfilfah\AndroidStudioProjects\game\core\build\libs

Also made a new folder for testing if it will work:

C:\Users\zfilfah\AndroidStudioProjects\game\core\libs

What am I missing? What more should I do to make Tween Engine work on my libGDX Android Studio?

Android gradle:

android {
    buildToolsVersion "23.0.2"
    compileSdkVersion 23
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
        }

        instrumentTest.setRoot('tests')
    }
    defaultConfig {
        applicationId "com.mygdx.game"
        minSdkVersion 8
        targetSdkVersion 23
    }
}


// called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives() { 
    file("libs/armeabi/").mkdirs();
    file("libs/armeabi-v7a/").mkdirs();
    file("libs/arm64-v8a/").mkdirs();
    file("libs/x86_64/").mkdirs();
    file("libs/x86/").mkdirs();

    configurations.natives.files.each { jar ->
        def outputDir = null
        if(jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
        if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")        
        if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
        if(jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")
        if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
        if(outputDir != null) {
            copy {
                from zipTree(jar)
                into outputDir
                include "*.so"
            }
        }
    }
}

task run(type: Exec) {
    def path
    def localProperties = project.file("../local.properties")
    if (localProperties.exists()) {
        Properties properties = new Properties()
        localProperties.withInputStream { instr ->
            properties.load(instr)
        }
        def sdkDir = properties.getProperty('sdk.dir')
        if (sdkDir) {
            path = sdkDir
        } else {
            path = "$System.env.ANDROID_HOME"
        }
    } else {
        path = "$System.env.ANDROID_HOME"
    }

    def adb = path + "/platform-tools/adb"
    commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.mygdx.game/com.mygdx.game.AndroidLauncher'
}

// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
    // need to specify Java source sets explicitly, SpringSource Gradle Eclipse plugin
    // ignores any nodes added in classpath.file.withXml
    sourceSets {
        main {
            java.srcDirs "src", 'gen'
        }
    }

    jdt {
        sourceCompatibility = 1.6
        targetCompatibility = 1.6
    }

    classpath {
        plusConfigurations += [ project.configurations.compile ]        
        containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'       
    }

    project {
        name = appName + "-android"
        natures 'com.android.ide.eclipse.adt.AndroidNature'
        buildCommands.clear();
        buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
        buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
        buildCommand "org.eclipse.jdt.core.javabuilder"
        buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
    }
}

// sets up the Android Idea project, using the old Ant based build.
idea {
    module {
        sourceDirs += file("src");
        scopes = [ COMPILE: [plus:[project.configurations.compile]]]        

        iml {
            withXml {
                def node = it.asNode()
                def builder = NodeBuilder.newInstance();
                builder.current = node;
                builder.component(name: "FacetManager") {
                    facet(type: "android", name: "Android") {
                        configuration {
                            option(name: "UPDATE_PROPERTY_FILES", value:"true")
                        }
                    }
                }
            }
        }
    }
}

Core gradle:

apply plugin: "java"

sourceCompatibility = 1.6
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

sourceSets.main.java.srcDirs = [ "src/" ]


eclipse.project {
    name = appName + "-core"


}
Filip
  • 127
  • 11

2 Answers2

1

Here is a solution:

  1. Place two jars into libs folder
  2. Open your project folder and find build.gradle file -- this is a root build
  3. Add this line compile fileTree(dir: '../libs', include: '*.jar') under dependencies section in "core" and "android" projects.
  4. Add those 2 tween engine jars to modules dependencies in IDE.
  5. Sync project with gradle.
Enigo
  • 3,685
  • 5
  • 29
  • 54
  • I can't find the dependencies section I added the core and android code in my first post. – Filip Feb 16 '16 at 15:39
  • Read carefully: 2. Open your **project folder** and find `build.gradle` file -- this is a root build. It is located NOT in android or core folders, but in the root of your project – Enigo Feb 16 '16 at 15:54
  • Thank you, now I understand. But I'm not sure if Tween Engine works. I can't implement the TweenAccessor in my class. – Filip Feb 16 '16 at 16:15
  • Any errors? Did you sync your project successfully after changes? – Enigo Feb 16 '16 at 16:33
  • Error:Execution failed for task ':core:compileJava'. > Compilation failed; see the compiler error output for details. // when I rebuild Project. – Filip Feb 16 '16 at 16:50
  • try to add those 2 jars of tween engine as dependencies in your IDE. right click on core module -> Open Module Settings -> tab dependencies. here a "plus" sign -> Library and then choose jars. I'll update my answer. – Enigo Feb 16 '16 at 17:24
0

Further to other answers for me changing:

compile fileTree(dir: 'libs', include: '*.jar')

to:

compile fileTree(dir: '../libs/tween-engine-api-6.3.3 2', include: '*.jar')

did the trick. (Obviously your file name may be different (no 2 at the end for example))

mmmartinnn
  • 387
  • 4
  • 16