在Instant App中应用插件“kotlin-android”会导致“null不能转换为非空类型的com.android.build.gradleBasePlugin”
我一直在试图将最新公开发布的Android即时应用与Kotlin编程语言结合起来。 在使用以下(标准?)设置创建我的项目后,当我尝试构建应用程序时,出现错误消息“null不能转换为非空类型com.android.build.gradle.BasePlugin” 。 使用Kotlin可以很好的使用标准的“com.android.application”模块; 只有当我尝试在即时应用程序模块中使用它时,才会引发错误。
顶级build.gradle :
buildscript { repositories { maven { url 'https://maven.google.com' } jcenter() } dependencies { classpath "com.android.tools.build:gradle:3.0.0-alpha1" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2-4" } } // ...
应用程序模块build.gradle ,其中Kotlin工作:
apply plugin: 'com.android.application' apply plugin: 'kotlin-android' // This will work. android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { // ... } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { implementation project(':feature') implementation project(':base') }
基本模块build.gradle ,其中Kotlin 不起作用 :
apply plugin: 'com.android.feature' apply plugin: 'kotlin-android' // This won't work. android { compileSdkVersion 25 buildToolsVersion "25.0.2" baseFeature true defaultConfig { // ... } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { feature project(':tracker') compile 'com.android.support:appcompat-v7:25.+' compile 'com.android.support.constraint:constraint-layout:1.0.2' // Kotlin standard library. compile "org.jetbrains.kotlin:kotlin-stdlib:${gradleKotlinVersion}" }
instantapp模块build.gradle :
apply plugin: 'com.android.instantapp' dependencies { implementation project(':feature') implementation project(':base') }
功能模块build.gradle :
apply plugin: 'com.android.feature' android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { // ... } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } 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' }) implementation project(':base') testCompile 'junit:junit:4.12' }
再次, 应用程序模块编译没有这个配置的问题; 另一方面,Android Studio / Gradle给了我这个奇怪的“null不能转换为非null类型com.android.build.gradle.BasePlugin”的错误信息,建议重新下载依赖关系并同步项目(done )或重新启动Android Studio。
即时应用程序是否与Kotlin编程语言实际兼容? 我很期待你的回答:)
PS:我使用Android Studio 3.0 Canary 1,从Canary Channel for Build工具等安装最新的更新。我的Kotlin插件也应该是最新的。
这在Kotlin插件v1.1.2-5中解决 。 请更新您的版本,然后重试。
作为参考,以前的插件版本的问题正在跟踪:
38393607 | 问题建立启用Kotlin的即时应用程序
- 安科 – 替代隐藏一个观点,并显示另一个
- 代码@TypeConverterAnnotation是什么意思?
- 无法访问Kotlin中的val
- 如何在我的应用程序及其库中实例化一个Singleton?
- 在anko DSL中相当于<fragment>标签
- 如何在Android Activity上使用Kotlin扩展函数进行空检查
- 如何将Firebase中的文本文件读取到Android应用程序
- java.lang.ClassNotFoundException:com.intellij.junit5.JUnit5IdeaTestRunner在kotlin中使用spek
- 我怎样才能注入对象到android kotlin MVP mosby应用程序与匕首的主持人