库项目显示错误的模块

时间:2018-04-22 13:35:31

标签: android android-studio gradle libgdx android-gradle

我有两个项目并排

  1. 包含两个模块的库 - 自定义视图和示例应用程序
  2. 具有多个模块的LibGdx应用程序,具体取决于库项目
  3. 问题是,当我在Android Studio中打开库项目时,它会显示LibGdx项目中的所有模块以及它自己的两个模块。这意味着我甚至无法构建示例应用程序,因为运行配置只允许选择LibGdx项目的“android”模块。 (意思是我只能使用android模块清单中的类)

    我认为问题必须与LibGdx生成的gradle文件有关,但我找不到问题。

    图书馆计划 settings.gradle

    include ':customview', ':customviewtestapp'
    

    图书馆项目; root build.gradle

    buildscript {
        repositories { ... }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.1.1'
        }
    }
    
    allprojects { repositories { ... } }
    
    task clean(type: Delete) { delete rootProject.buildDir }
    

    图书馆项目; customview模块 build.gradle

    apply plugin: 'com.android.library'
    
    android {
        ....
        buildTypes {
            release ...
        }
    }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        ... //appcompat stuff
    }
    

    LibGdx项目 settings.gradle

    include ':android', ':core', 'textfieldboxes', 'customview'
    project(":textfieldboxes").projectDir = file("../TextFieldBoxes/textfieldboxes")
    project(":customview").projectDir = file("../CustomView/customview")
    

    LibGdx项目; root build.gradle

    buildscript {
        repositories { ... }
        dependencies { classpath 'com.android.tools.build:gradle:3.1.1' }
    }
    
    allprojects {
        apply plugin: "idea"
        version = '1.0'
        ext {
            appName = "MyApp"
            gdxVersion = '1.9.8'
            roboVMVersion = '2.3.3'
            ...
        }
    
        repositories { ... }
    }
    
    project(":android") {
        apply plugin: "android"
        configurations { natives }
    
        dependencies {
            implementation project(":core")
            implementation "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
            ... //Gdx Natives
        }
    }
    
    project(":core") {
        apply plugin: "java"
    
        dependencies {
            ... //only Gdx dependencies
        }
    }
    

    LibGdx项目; android模块 build.gradle

    android {
        buildToolsVersion "27.0.3"
        compileSdkVersion 27
        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                aidl.srcDirs = ['src']
                renderscript.srcDirs = ['src']
                res.srcDirs = ['res']
                assets.srcDirs = ['assets']
                jniLibs.srcDirs = ['libs']
            }
            androidTest.setRoot('tests')
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
        packagingOptions {
            exclude 'META-INF/robovm/ios/robovm.xml'
        }
        defaultConfig {
            applicationId "com.my.app"
            ...
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        dependencies {
            ...
            implementation project(':textfieldboxes')
            implementation project(':customview')
            annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
        }
    }
    
    task copyAndroidNatives() {
        file("libs/x86/").mkdirs() //var othersious
        configurations.natives.files.each { jar ->
            def outputDir = null
            if (jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
            ... //various others
            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.my.app/com.my.app.AndroidLauncher'
    }
    
    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")
                            }
                        }
                    }
                }
            }
        }
    }
    

    项目根目录都位于我的用户下的“StudioProjects”目录中,但是在单独的子目录中,我在某些时候在两个IDE窗口中打开了两个项目

0 个答案:

没有答案