在另一个Android模块中使用Android库

时间:2016-01-13 14:07:21

标签: java android android-library

我的项目中有3个模块:

Modules

在'ia'模块中,我使用ndk作为加载C代码。

在'android'中我有我的游戏菜单。

在'核心'我有我的图形界面(libgdx)。

我希望在核心中使用'ia'。

当我输入“import eu.epitech.ia”时,我有一个错误:“找不到符号类ia”。

在build.gradle中添加依赖项“compile project(':ia')。

我不知道如何在“核心”模块中使用我的IA类。

android build.gradle

apply plugin: "com.android.model.application"

model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.2"
        defaultConfig.with {
            applicationId = "eu.epitech.gomoku.android"
            minSdkVersion.apiLevel = 4
            targetSdkVersion.apiLevel = 23
        }
    }

    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles.add(file("proguard-rules.pro"))
        }
    }

    android.sources {
        main {
            manifest {
                source {
                    srcDir "."
                    include "AndroidManifest.xml"
                }
            }
            res {
                source {
                    srcDir "res"
                }
            }
            assets {
                source {
                    srcDir "assets"
                }
            }
            java {
                source {
                    srcDir "src"
                }
            }
            jniLibs {
                source {
                    srcDir "libs"
                }
            }
            jni {
                source {
                    srcDir "jni"
                }
            }
        }
    }

}
// 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/x86/").mkdirs();

    configurations.natives.files.each { jar ->
        def outputDir = null
        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.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", "eu.epitech.gomoku.android/eu.epitech.gomoku.android.AndroidLauncher"
}
// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
    // need to specify Java source sets explicitely, 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")
                        }
                    }
                }
            }
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile "com.android.support:support-v4:23.+"
    compile project(':ia')
}

//apply plugin: 'com.android.model.application'
//
//dependencies {
//    compile project(':ia')
//}

ia build.gradle

apply plugin: "com.android.model.library"

model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.2"
        defaultConfig.with {
            minSdkVersion.apiLevel = 4
            targetSdkVersion.apiLevel = 23
        }
    }

    android.ndk {
        moduleName = "hello-jni"
    }

    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles.add(file("proguard-rules.pro"))
        }
    }

    android.productFlavors {
        // for detailed abiFilter descriptions, refer to "Supported ABIs" @
        // https://developer.android.com/ndk/guides/abis.html#sa
        create("arm") {
            ndk.abiFilters.add("armeabi")
        }
        create("arm7") {
            ndk.abiFilters.add("armeabi-v7a")
        }
        create("arm8") {
            ndk.abiFilters.add("arm64-v8a")
        }
        create("x86") {
            ndk.abiFilters.add("x86")
        }
        create("x86-64") {
            ndk.abiFilters.add("x86_64")
        }
        create("mips") {
            ndk.abiFilters.add("mips")
        }
        create("mips-64") {
            ndk.abiFilters.add("mips64")
        }
        // To include all cpu architectures, leaves abiFilters empty
        create("all")
    }

    android.sources {
        main {
            manifest {
                source {
                    srcDir "."
                    include "AndroidManifest.xml"
                }
            }
            res {
                source {
                    srcDir "res"
                }
            }
            assets {
                source {
                    srcDir "assets"
                }
            }
            java {
                source {
                    srcDir "src"
                }
            }
            jniLibs {
                source {
                    srcDir "libs"
                }
            }
            jni {
                source {
                    srcDir "jni"
                }
            }
        }
    }

}

core build.gradle

apply plugin: "java"
sourceCompatibility = 1.6
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceSets.main.java.srcDirs = ["src/"]
eclipse.project {
    name = appName + "-core"
}
dependencies {

}

由于

1 个答案:

答案 0 :(得分:-1)

您是否尝试过添加到build.graddle这一行compile project(':ia')

    dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:22.2.1'

    compile project(':ia')}