简体   繁体   English

Android工作室用实验gradle 0.2.0

[英]Android studio with experimental gradle 0.2.0

I am trying to setup a basic ndk build with the latest version of android studio at this moment. 我正在尝试用最新版本的android studio设置一个基本的ndk版本。 Trying to follow this tutorial 试着按照本教程

在此输入图像描述

This is my gradle-wrapper.properties 这是我的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 这是项目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 这是我的模块的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. 第10行是:minSdkVersion = 10您可以在我上面的build.gradle中看到整个文件。

edit 编辑

As @unbekant pointed out in his comment and the link to this post 正如@unbekant在他的评论和这篇文章的链接中指出的那样

The min and target sdk values should be set like this: min和target sdk值应该设置如下:

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之外

android.buildTypes
android.sources
android.productFlavors

Also the buildConfigFields.with should be inside the defaultConfig or inside the buildTypes or productFlavors : buildConfigFields.with应该在defaultConfigbuildTypesproductFlavors

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 . 此外,最后一个版本是0.2.1

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

There's a tutorial? 有一个教程? Oh, that. 哦这个。 Where are the links? 链接在哪里?

The current version is 0.2.0. 目前的版本是0.2.0。

or dates? 还是约会?

I googled every one of the missing files individually (maybe 3 dozen!) after adding: 添加后,我分别搜索了每个丢失的文件(可能是3打!)

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

I tried the alpha version too but I failed finding some of its dependencies altogether. 我也尝试了alpha版本,但我没有完全找到它的一些依赖项。

First I get a couple of dependencies I can be bothered chasing down: 首先,我得到一些依赖,我可能会被打扰追逐:

> Error:Could not find com.android.tools.build:gradle-experimental:0.2.1.
Searched in the following locations:
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle-experimental/0.2.1/gradle-experimental-0.2.1.pom
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle-experimental/0.2.1/gradle-experimental-0.2.1.jar

Once each of these was added to the given path seven more would sprout up in its place. 一旦将这些中的每一个添加到给定路径中,就会有七个在它的位置发芽。 If someone could post how to automatically update these (they still aren't in the latest 1.4RC1 Android Studio) it would be very useful. 如果有人可以发布如何自动更新这些内容(它们仍然不在最新的1.4RC1 Android Studio中),那将非常有用。 I got most of the stuff from maven, eg http://mvnrepository.com/artifact/com.android.tools.lint/lint-checks/24.3.1 我从maven获得了大部分内容,例如http://mvnrepository.com/artifact/com.android.tools.lint/lint-checks/24.3.1

I got all the files to shut up Gradle's whining and you know what it said? 我得到了所有文件来关闭Gradle的抱怨,你知道它说了什么吗?

     Error:(34, 1) A problem occurred evaluating project ':app'.
> Error: NDK integration is deprecated in the current plugin.  Consider trying the new experimental plugin.  For details, see http://tools.android.com/tech-docs/new-build-system/gradle-experimental.  Set "android.useDeprecatedNdk=true" in gradle.properties to continue using the current NDK integration.

Which was exactly the error that led me to migrate to experimental and no better than the stock 1.3.0 that ships with AS (though it was defaulting to 1.2.3). 这正是导致我迁移到实验的错误,并不比AS附带的股票1.3.0更好(尽管它默认为1.2.3)。

Why did I bother? 我为什么这么烦? I want to debug NDK and couldn't see what else I wasn't doing apart from not using an experimental build. 我想调试NDK,除了不使用实验版本之外,我看不出还有什么不做。

This goose chase was just a big waste of time. 这种鹅追逐只是浪费时间。 I'm back to using 我回去使用了

android.useDeprecatedNdk=true

No doubt I can fix it somewhere else but just a warning to others chasing experimental dependencies; 毫无疑问,我可以在其他地方修复它,但只是警告其他人追逐实验依赖; they are unicorns. 他们是独角兽。

@jonagon Some examples are in this repo: @jonagon这个回购中有一些例子:
https://github.com/googlesamples/android-ndk https://github.com/googlesamples/android-ndk

probably could try: 可能会尝试:

jni folder issue: jni文件夹问题:

  1. it is default for gradle experimental plugin, also for older c++ support NOT using gradle-experimental plugin ( android plugin ) 它是gradle实验插件的默认设置,也适用于较旧的c ++支持,不使用gradle-experimental插件(android插件)

  2. if you have that folder and not using experimental plugin, Gradle thinks that app is using the older android studio c++ support. 如果您有该文件夹而不使用实验性插件,Gradle认为该应用程序正在使用较旧的android studio c ++支持。 It gives your that warning "NDK integration is deprecated in the current plugin" and recommend you to experimental plugin. 它给出了警告“NDK集成在当前插件中已弃用”,并建议您使用实验性插件。 it could be silenced with: 它可能会沉默:

    • sourceSets.main.jni.srcDirs = [] sourceSets.main.jni.srcDirs = []

or just rename that jni folder to something else: it will cause more trouble if you want to android-studio cmake/ndk-build in the future, rename is better. 或者只是将jni文件夹重命名为其他内容:如果你想在未来使用android-studio cmake / ndk-build,会导致更多麻烦,重命名更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM