在Instant App中应用插件“kotlin-android”会导致“null不能转换为非空types的com.android.build.gradleBasePlugin”
我一直在试图将新公开发布的Android即时应用和Kotlin编程语言结合起来。 在使用以下(标准?)设置创建我的项目后,当我尝试构建应用程序时,出现错误消息“null不能转换为非空typescom.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') }
function模块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不能转换为非nulltypescom.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的即时应用程序
参考谷歌问题跟踪器 ,这已被修复。 同时,您可以手动更新到1.1.3 kotlin插件。
如果问题仍然存在,请在Google问题跟踪器中报告,他们将重新审核。
- 升级到android gradle插件3.0.0+后,项目不会生成
- 是否有可能使用Java 8进行Android开发?
- 未找到Android Studio 3 appcompat资源
- Android数据绑定构建失败后,Gradle插件更新迁移到annotationProcessor
- 在将Android Studio更新到2.3.1和Gradle之后,应用程序崩溃并出现ClassNotFoundException
- 在gradle android库kotlin项目中禁用META-INF / *生成
- 重复的zip文件))
- Android Studio执行失败的任务compilefreeDebugKotlin
- 错误:执行任务’:app:clean’失败。 无法删除文件