gpt4 book ai didi

android - 顶级 build.gradle 文件中的 ext 属性

转载 作者:行者123 更新时间:2023-12-03 17:43:56 28 4
gpt4 key购买 nike

我正在开发一个安卓应用程序。我在根项目中有一个“dependencies.gradle”文件:

ext {
// Android
kotlinVersion = '1.2.51'
gradleVersion = '3.1.3'
}

问题是我可以在 App 'build.gradle' 文件中使用此属性,但不能在 Root 'build.gradle' 文件中使用,它给了我这个错误:
Could not get unknown property 'kotlinVersion' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

这是我的“根构建 Gradle”:
apply from: 'dependencies.gradle'

buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.1.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}

allprojects {
repositories {
google()
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

这是我的“App Build Gradle”:
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 27
defaultConfig {
applicationId "com.shimibox.client"
minSdkVersion 18
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

最佳答案

我发现了问题。 ext 必须在 buildscript block 内。所以我移动了apply from: 'dependencies.gradle'在那个街区里面。
现在 Root build.gradle 文件是:

buildscript {

apply from: 'dependencies.gradle'

repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.1.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}

关于android - 顶级 build.gradle 文件中的 ext 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51542129/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com