Android gradle-experimental 0.2.0 add res and aidl

2019-07-01 20:10发布

I'm struggling to use external library in Android Studio 1.3, Gradle 2.5 and gradle-experimental plugin 0.2.0, required because of NDK.

I found some material here on how to change old gradle files which I've done, but can't find any other documentation documentation.

During my extensive search I managed to find out the changes for manifest but not for res and aid. Has anyone managed to find out what need to be changed or any useful documentation?

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

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle-experimental:0.2.0'
    }
}

model {
    android {
        compileSdkVersion = 19
        buildToolsVersion = "19.1.0"

        defaultConfig.with {
            applicationId = "org.opencv.android"
            minSdkVersion.apiLevel = 8
            targetSdkVersion.apiLevel = 19
            versionCode = 3000
            versionName = "3.0.0"
        }
    }

    android.sources {
        main {
            manifest.source.include 'AndroidManifest.xml' // OLD manifest.srcFile 'AndroidManifest.xml'
            java.source.srcDir 'src'
            resources.source.srcDirs 'src'
            res.srcDirs = ['res'] // ERROR
            aidl.srcDirs ['src'] // ERROR
        }
    }
}

The errors are:

Gradle sync failed: Could not find property 'srcDirs' on AndroidLanguageSourceSet 'main:aidl'.

Gradle sync failed: Unable to load class 'com.android.build.gradle.model.AndroidLanguageSourceSet_Decorated'.

1条回答
\"骚年 ilove
2楼-- · 2019-07-01 20:32

Some debugging with println shows that java, res, aidl are of the type AndroidLanguageSourceSet. They all have the same source property now, and srcDirs list inside that. You should be able to append your custom paths to the srcDirs property like:


android.source {
  main {
    java.source.srcDirs += 'src'
    res.source.srcDirs += 'res'
    aidl.source.srcDirs += 'aidl'
  }
}

Don't forget to use = in the new syntax to set the value and += to append it to the list (in the old syntax just a whitespace was sufficient).

查看更多
登录 后发表回答