android实验2,Android工作室用实验gradle 0.2.0

我正在尝试用最新版本的android studio设置一个基本的ndk版本.试图遵循this tutorial

1adf922473c8d5f328eebacf652d5e21.png

这是我的gradle-wrapper.properties

#Thu Sep 17 14:22:34 CST 2015

distributionBase=GRADLE_USER_HOME

distributionPath=wrapper/dists

zipStoreBase=GRADLE_USER_HOME

zipStorePath=wrapper/dists

distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip

这是项目build.gradle

// 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-experimental:0.2.0'

// NOTE: Do not place your application dependencies here; they belong

// in the individual module build.gradle files

}

}

allprojects {

repositories {

jcenter()

}

}

task clean(type: Delete) {

delete rootProject.buildDir

}

这是我的模块的build.gradle

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

model {

android {

compileSdkVersion = 23

buildToolsVersion = "23.0.1"

defaultConfig.with {

applicationId = "me.blubee.testnative_exp"

minSdkVersion = 10

targetSdkVersion = 23

versionCode = 1

versionName = "1.0"

}

buildConfigFields.with {

create() {

type = "int"

name = "VALUE"

value = "1"

}

}

android.buildTypes {

release {

minifyEnabled = false

proguardFiles += file('proguard-rules.pro')

}

}

android.productFlavors {

create("flavor1") {

applicationId = 'com.app'

}

}

android.sources {

main {

java {

source {

srcDir 'src'

}

}

}

}

}

}

我的项目结构如下所示:

APP

Java/

Java/android.support

Java/com.test.test_experimental

Java/com.test.test_experimental/R

Java/com.test.test_experimental

Java/com.test.test_experimentalBuildConfig

Java/com.test.test_experimental

Java/com.test.test_experimental/MainActivity

tests/

tests/com.test.test_experimental

tests/com.test.test_experimental/ApplicationTest.java

tests/com.test.test_experimental

tests/com.test.test_experimental/BuildConfig.java

resources/

test-resources

gradle/scripts/

我收到这些错误:

2:51:31 PM Gradle sync started

2:51:34 PM Gradle sync failed: Unable to load class 'com.android.build.gradle.managed.ProductFlavor_Impl'.

Consult IDE log for more details (Help | Show Log)

Error:Unable to load class 'com.android.build.gradle.managed.ProductFlavor_Impl'.

Possible causes for this unexpected error include:

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

Brother:TestNative_exp blubee$./gradlew clean --stacktrack

FAILURE: Build failed with an exception.

* Where:

Build file '/Users/bb/TestNative_exp/app/build.gradle' line: 10

* What went wrong:

A problem occurred configuring project ':app'.

> Exception thrown while executing model rule: model.android

> Cannot set readonly property: minSdkVersion for class: com.android.build.gradle.managed.ProductFlavor_Impl

* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2.619 secs

第10行是:minSdkVersion = 10

您可以在我上面的build.gradle中看到整个文件.

编辑

正如@unbekant在他的评论和this post的链接中指出的那样

min和target sdk值应该设置如下:

minSdkVersion.apiLevel = 15

targetSdkVersion.apiLevel = 22

我也试过了,我收到了这个错误:

* What went wrong:

A problem occurred configuring project ':app'.

> Exception thrown while executing model rule: model.android

> No such property: buildConfigFields for class: com.android.build.gradle.managed.AndroidConfig

* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

我究竟做错了什么?

解决方法:

你必须将这些块放在android块之外.

android.buildTypes

android.sources

android.productFlavors

buildConfigFields.with也应该在defaultConfig内或buildTypes或productFlavors中:

就像是:

model {

android {

compileSdkVersion = 22

buildToolsVersion = "22.0.1"

defaultConfig.with {

//----

minSdkVersion.apiLevel = 10

targetSdkVersion.apiLevel = 23

buildConfigFields.with {

create() {

//....

}

}

}

}

android.buildTypes {

release {

//

}

}

android.productFlavors {

//

}

// Configures source set directory.

android.sources {

//

}

}

此外,最后一个版本是0.2.1.

classpath 'com.android.tools.build:gradle-experimental:0.2.1'

标签:android,android-studio,gradle,android-gradle,build-gradle

来源: https://codeday.me/bug/20190611/1221617.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值