gpt4 book ai didi

android - Gradle不选择在lib文件夹下动态复制的库

转载 作者:行者123 更新时间:2023-12-03 05:56:47 26 4
gpt4 key购买 nike

我需要为apk执行和单元测试用例执行加载不同的运行时库。

我熟悉compile和testCompile范围,但是问题是我不想在运行单元测试时加载特定的编译范围库。

所以我想出了一些build.gradle,如下所示。我可以将所需的jar / aars复制到libs文件夹下,但这些文件不被视为类路径。

这个脚本有什么问题吗?

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "example.com.myapplication"
minSdkVersion 21
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

task getDynamicJars(type: Copy) {
delete fileTree("$projectDir/libs/")
if(project.gradle.startParameter.taskNames.contains("test")){
println("Loading Unit test dependencies");
from "$rootDir/runtimeLibs/test/"
into "$projectDir/libs/"
include '**/*.*'

}else{
println("Loading Execute dependencies from:"+"$projectDir/runtimeLibs/execution/"+" To:"+"$projectDir/libs/");
from "$rootDir/runtimeLibs/execution/"
into "$projectDir/libs/"
include '**/*.*'
}

}

dependencies {
println("Loading dependencies");
compile fileTree(dir: "libs", include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.0'
testCompile 'junit:junit:4.12'
}

project.afterEvaluate {
preBuild.dependsOn getDynamicJars
}

最佳答案

您如何看待此解决方案:

def libsFolder
// ..
buildTypes {
release {
// ..
libsFolder = "${releaseLibsDir}"
}

debug {
// ..
libsFolder = "${debugLibsDir}"
}
}
// ..
dependencies {
compile fileTree(dir: "${libsFolder}", include: ['*.jar'])
}

关于android - Gradle不选择在lib文件夹下动态复制的库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44416131/

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