java - 安卓gradle配置java 1.8
问题描述
我正在尝试使用 Java 插件为 Android 项目配置 Gradle。该项目包含一个 Android 库和 Android 应用程序。应用程序使用库来执行一些操作。这是我的应用程序的 gradle 文件:
apply plugin: 'java'
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion 27
buildToolsVersion "27.0.2"
defaultConfig{
applicationId "xxxxxxxxx"
minSdkVersion.apiLevel 19
targetSdkVersion.apiLevel 27
versionCode 1
versionName "0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles.add(file("proguard-rules.pro"))
}
}
}
compileJava{
sourceCompatilibity = 1.8
targetCompatibility = 1.8
}
}
repositories {
jcenter()
maven {
url 'https://maven.google.com'
}
flatDir {
dirs 'libs'
}
}
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 project(path: ':my_library')
testCompile 'junit:junit:4.12'
}
gradle编译显示的错误如下:
无法使用创建规则“BaseComponentModelPlugin.Rules#createRemainingTasks(ModelMap, TaskManager, ModelMap) > create(test)”创建“tasks.test”,因为规则“Project..tasks.test()”已注册以创建此模型元素.
我已经读过在 Gradle 中包含 java 插件会自动添加一个测试任务,我会删除它,但我需要使用 Java 1.8 来编译项目。任何有关此错误的帮助/提示将不胜感激,谢谢。
更新: 最后我设法配置了项目。由于我必须使用 gradle-experimental(我正在使用需要它的 NDK 依赖项),我唯一的选择是将最低 API 级别升级到 26 并删除 Java 1.8 兼容性,这是我最终的 build.gradle 文件:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 27
buildToolsVersion = "27.0.2"
defaultConfig.with {
applicationId = "xxxxxxxxxx"
minSdkVersion.apiLevel = 26
targetSdkVersion.apiLevel = 27
versionCode = 1
versionName = "0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles.add(file('proguard-android.txt'))
}
}
}
}
repositories {
jcenter()
google()
flatDir {
dirs 'libs'
}
}
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 project(path: ':my-library')
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:27.0.2'
testCompile 'junit:junit:4.12'
// Brings the new BluetoothLeScanner API to older platforms
compile 'no.nordicsemi.android.support.v18:scanner:1.1.0'
// BLE library
compile 'no.nordicsemi.android:ble:1.2.0'
}
解决方案
推荐阅读
- ubuntu-18.04 - GRUB 引导选项?(Ubuntu 18)
- c - 指向数组第一个元素之前的指针
- c# - C#到微控制器的串行通信问题
- vue.js - 在 Vue js 中使用颜色选择器更改字体(文本)颜色
- java - 如何将传感器数据从作为服务器的arduino发送到tomcat上的jsp?
- python - Python 虚拟环境不使用 Cloud9 中的 venv 包
- laravel - 强制松弛登录到队列中
- vb.net - 使用 vb .net 在 microsoft crm 中的电子邮件中添加本地 pdf 附件
- php - 重命名列 Laravel 5.8 后从表中删除数据
- tcp - Mule4 支持 TCP 连接