我试图像在groovy中那样组织我的构建文件,通过在单独的文件中重用值来重用.但我无法理解在kotlin DSL中做同样事情的语法.
这是我在root build.gradle.kts中使用的内容:
applyFrom("config.gradle.kts")
buildscript {
repositories {
google()
jcenter()
}
dependencies {
val test = project.extra["minSdkVer"]
classpath("com.android.tools.build:gradle:3.0.0-alpha4")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2-5")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
Run Code Online (Sandbox Code Playgroud)
以下是正在引用的config.gradle.kts中的内容:
mapOf(
Pair("minSdkVer", 22),
Pair("targetSdkVer", 25),
Pair("compiledSdkVer", 25),
Pair("buildToolsVer", "26-rc4")
).entries.forEach {
project.extra.set(it.key, it.value)
}
Run Code Online (Sandbox Code Playgroud)
但是有一个错误:
无法在额外的属性扩展上获取属性'minSdkVer',因为它不存在
我正在尝试将应用程序拆分为abi特定的apks,但所有apks的版本号都是相同的.他们需要不同才能上传到游戏商店.我错过了什么吗?
splits {
abi {
enable true
reset()
include 'x86', 'armeabi', 'armeabi-v7a', 'arm64-v8a'
universalApk true
}
}
Run Code Online (Sandbox Code Playgroud) 我和Dagger有一些奇怪的kotlin泛型问题,我有点固定,但解决方案并不合理.
这是匕首类:
@Module class P5Module {
@Provides fun pool(): RecyclerView.RecycledViewPool = RecyclerView.RecycledViewPool()
@Provides
fun adapters(fusion: P5FusionAdapter, personas: P5ListAdapter, skills: P5SkillsAdapter, info: InfoAdapter)
: List<Pageable> = listOf(fusion, personas, skills, info)
}
@ActivityScope
@Subcomponent(modules = arrayOf(P5Module::class)) interface P5Component {
fun adapter(): PageableAdapter
}
interface Pageable {
fun manager(ctx: Context): LayoutManager
fun attach()
fun adapter(): Adapter<*>
}
class PageableAdapter
@Inject constructor(val pageables: List<Pageable>, val pool: RecyclerView.RecycledViewPool) :PagerAdapter()
Run Code Online (Sandbox Code Playgroud)
当我构建时,我在顶级组件中得到了这个kapt错误:
e: C:\Users\daykm\StudioProjects\P5Executioner\app\build\tmp\kapt3\stubs\appDebug\com\daykm\p5executioner\AppComponent.java:17: error: [com.daykm.p5executioner.main.P5Component.adapter()] java.util.List<? extends com.daykm.p5executioner.view.Pageable> cannot be provided without an @Provides-annotated method.
e: …Run Code Online (Sandbox Code Playgroud)