带有实验 gradle 0.2.0 的 Android Studio [英] Android studio with experimental gradle 0.2.0
问题描述
我现在正在尝试使用最新版本的 android studio 设置基本的 ndk 构建.尝试遵循
这是我的gradle-wrapper.properties
#Thu Sep 17 14:22:34 CST 2015distributionBase=GRADLE_USER_HOME分布路径=包装器/distszipStoreBase=GRADLE_USER_HOMEzipStorePath=wrapper/distsdistributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip
这是项目 build.gradle
//顶级构建文件,您可以在其中添加所有子项目/模块通用的配置选项.构建脚本{存储库{jcenter()}依赖{类路径 'com.android.tools.build:gradle-experimental:0.2.0'//注意:不要将您的应用程序依赖项放在这里;他们属于//在单独的模块 build.gradle 文件中}}所有项目{存储库{jcenter()}}任务清理(类型:删除){删除 rootProject.buildDir}
这是我的模块的 build.gradle
应用插件:'com.android.model.application'模型 {安卓 {compileSdkVersion = 23buildToolsVersion = "23.0.1"defaultConfig.with {applicationId = "me.bluebee.testnative_exp"minSdkVersion = 10目标SDK版本= 23版本代码 = 1版本名称 = "1.0"}buildConfigFields.with {创建() {类型 = "int"名称 = "值"值 = "1"}}android.buildTypes {释放 {minifyEnabled = falseproguardFiles += file('proguard-rules.pro')}}android.productFlavors {创建(风味1"){applicationId = 'com.app'}}android.sources {主要的 {爪哇{来源 {srcDir 'src'}}}}}}
我的项目结构如下:
APP爪哇/Java/android.supportJava/com.test.test_experimentalJava/com.test.test_experimental/RJava/com.test.test_experimentalJava/com.test.test_experimentalBuildConfigJava/com.test.test_experimentalJava/com.test.test_experimental/MainActivity测试/测试/com.test.test_experimental测试/com.test.test_experimental/ApplicationTest.java测试/com.test.test_experimental测试/com.test.test_experimental/BuildConfig.java资源/测试资源毕业/脚本/
我收到这些错误:
2:51:31 PM Gradle 同步开始下午 2:51:34 Gradle 同步失败:无法加载类com.android.build.gradle.managed.ProductFlavor_Impl".有关更多详细信息,请参阅 IDE 日志(帮助 | 显示日志)错误:无法加载类com.android.build.gradle.managed.ProductFlavor_Impl".此意外错误的可能原因包括:- Gradle 的依赖项缓存可能已损坏(这有时发生在网络连接超时之后.)<a href="syncProject">重新下载依赖项并同步项目(需要网络)</a></li><li>Gradle 构建进程(守护进程)的状态可能已损坏.停止所有 Gradle 守护进程可能会解决这个问题.<a href="stopGradleDaemons">停止 Gradle 构建过程(需要重启)</a></li><li>您的项目可能使用了与其他插件不兼容的第三方插件在项目或项目请求的 Gradle 版本中.</li></ul>如果 Gradle 进程损坏,您也可以尝试关闭 IDE,然后杀死所有 Java 进程.兄弟:TestNative_exp blubee$ ./gradlew clean --stacktrackFAILURE:构建失败,出现异常.* 在哪里:构建文件 '/Users/bb/TestNative_exp/app/build.gradle' 行:10* 什么地方出了错:配置项目:app"时出现问题.>执行模型规则时抛出异常:model.android>无法为类设置只读属性:minSdkVersion:com.android.build.gradle.managed.ProductFlavor_Impl* 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪.使用 --info 或 --debug 选项运行以获得更多日志输出.构建失败总时间:2.619 秒
第 10 行是:minSdkVersion = 10你可以在我上面的 build.gradle
中看到整个文件.
编辑
正如@unbekant 在他的评论和指向 这篇文章
最小和目标 sdk 值应设置如下:
minSdkVersion.apiLevel = 15targetSdkVersion.apiLevel = 22
我也试过了,出现这个错误:
* 出了什么问题:配置项目:app"时出现问题.>执行模型规则时抛出异常:model.android>没有这样的属性:buildConfigFields 类:com.android.build.gradle.managed.AndroidConfig* 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪.使用 --info 或 --debug 选项运行以获得更多日志输出.构建失败
我做错了什么?
你必须把这些块放在外面 android
块.
android.buildTypesandroid.sourcesandroid.productFlavors
此外,buildConfigFields.with
应该在 defaultConfig
内或在 buildTypes
或 productFlavors
内:>
类似于:
model {安卓 {compileSdkVersion = 22buildToolsVersion = "22.0.1"defaultConfig.with {//----minSdkVersion.apiLevel = 10targetSdkVersion.apiLevel = 23buildConfigFields.with {创建() {//....}}}}android.buildTypes {释放 {//}}android.productFlavors {//}//配置源集目录.android.sources {//}}
另外,最后一个版本是0.2.1.
classpath 'com.android.tools.build:gradle-experimental:0.2.1'
I am trying to setup a basic ndk build with the latest version of android studio at this moment. Trying to follow this tutorial
This is my 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
This is the project 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
}
Here is my module's 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'
}
}
}
}
}
}
my project structure looks like this:
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/
I am getting these errors:
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:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
<a href="syncProject">Re-download dependencies and sync project (requires network)</a></li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
<a href="stopGradleDaemons">Stop Gradle build processes (requires restart)</a></li><li>Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.</li></ul>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
line #10 is: minSdkVersion = 10
You can see the whole file in the build.gradle
that i put above.
edit
As @unbekant pointed out in his comment and the link to this post
The min and target sdk values should be set like this:
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 22
I tried that as well, I get this error:
* 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
What am I doing wrong?
You have to put these blocks outside the android
block.
android.buildTypes
android.sources
android.productFlavors
Also the buildConfigFields.with
should be inside the defaultConfig
or inside the buildTypes
or productFlavors
:
Something like:
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 {
//
}
}
Also, the last version is 0.2.1.
classpath 'com.android.tools.build:gradle-experimental:0.2.1'
这篇关于带有实验 gradle 0.2.0 的 Android Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!