Android-studio ERROR: Cannot add task 'copyDebugIconFonts' as a task with that name already exists
Android-studio ERROR: Cannot add task 'copyDebugIconFonts' as a task with that name already exists
我有 React Native 项目。当我构建 Android 版本时,我得到一个 ERROR: Cannot add task 'copyDebugIconFonts' as a task with that name already exists .在我的终端我有这个错误:
FAILURE:构建失败,出现异常。
其中:
脚本“/Users/evgeniykireev/openCalls/node_modules/react-native-vector-icons/fonts.gradle”行:16
出了什么问题:
无法添加任务 'copyDebugIconFonts',因为同名任务已经存在。
我的build.gradle:
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.4.1")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
}
}
我的fonts.gradle:
def config = project.hasProperty("vectoricons") ? project.vectoricons : [];
def iconFontsDir = config.iconFontsDir ?: "../../node_modules/react-native-vector-icons/Fonts";
def iconFontNames = config.iconFontNames ?: [ "*.ttf" ];
gradle.projectsEvaluated {
android.applicationVariants.all { def variant ->
def targetName = variant.name.capitalize()
def targetPath = variant.dirName
// Create task for copying fonts
def currentFontTask = tasks.create(
name: "copy${targetName}IconFonts",
type: Copy) {
into("${buildDir}/intermediates")
iconFontNames.each { fontName ->
from(iconFontsDir) {
include(fontName)
into("assets/${targetPath}/fonts/")
}
// Workaround for Android Gradle Plugin 3.2+ new asset directory
from(iconFontsDir) {
include(fontName)
into("merged_assets/${variant.name}/merge${targetName}Assets/out/fonts/")
}
// Workaround for Android Gradle Plugin 3.4+ new asset directory
from(iconFontsDir) {
include(fontName)
into("merged_assets/${variant.name}/out/fonts/")
}
}
}
currentFontTask.dependsOn("merge${targetName}Resources")
currentFontTask.dependsOn("merge${targetName}Assets")
[
"processArmeabi-v7a${targetName}Resources",
"processX86${targetName}Resources",
"processUniversal${targetName}Resources",
"process${targetName}Resources"
].each { name ->
Task dependentTask = tasks.findByPath(name);
if (dependentTask != null) {
dependentTask.dependsOn(currentFontTask)
}
}
}
}
你能帮帮我吗)
此包“react-native-vector-icons”已多次添加到您的 build.gradle 文件中。
要解决此问题,只需转至 android>build.gradle 并搜索“react-native-vector-icons”。如果您发现了两次,则删除该行。例如我刚刚注释掉了这个=>
// 申请自:"../../node_modules/react-native-vector-icons/fonts.gradle"
就我而言,我删除了 Android/setting 中的这段代码。gradle
include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
我有 React Native 项目。当我构建 Android 版本时,我得到一个 ERROR: Cannot add task 'copyDebugIconFonts' as a task with that name already exists .在我的终端我有这个错误: FAILURE:构建失败,出现异常。
其中: 脚本“/Users/evgeniykireev/openCalls/node_modules/react-native-vector-icons/fonts.gradle”行:16
出了什么问题: 无法添加任务 'copyDebugIconFonts',因为同名任务已经存在。
我的build.gradle:
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.4.1")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
}
}
我的fonts.gradle:
def config = project.hasProperty("vectoricons") ? project.vectoricons : [];
def iconFontsDir = config.iconFontsDir ?: "../../node_modules/react-native-vector-icons/Fonts";
def iconFontNames = config.iconFontNames ?: [ "*.ttf" ];
gradle.projectsEvaluated {
android.applicationVariants.all { def variant ->
def targetName = variant.name.capitalize()
def targetPath = variant.dirName
// Create task for copying fonts
def currentFontTask = tasks.create(
name: "copy${targetName}IconFonts",
type: Copy) {
into("${buildDir}/intermediates")
iconFontNames.each { fontName ->
from(iconFontsDir) {
include(fontName)
into("assets/${targetPath}/fonts/")
}
// Workaround for Android Gradle Plugin 3.2+ new asset directory
from(iconFontsDir) {
include(fontName)
into("merged_assets/${variant.name}/merge${targetName}Assets/out/fonts/")
}
// Workaround for Android Gradle Plugin 3.4+ new asset directory
from(iconFontsDir) {
include(fontName)
into("merged_assets/${variant.name}/out/fonts/")
}
}
}
currentFontTask.dependsOn("merge${targetName}Resources")
currentFontTask.dependsOn("merge${targetName}Assets")
[
"processArmeabi-v7a${targetName}Resources",
"processX86${targetName}Resources",
"processUniversal${targetName}Resources",
"process${targetName}Resources"
].each { name ->
Task dependentTask = tasks.findByPath(name);
if (dependentTask != null) {
dependentTask.dependsOn(currentFontTask)
}
}
}
}
你能帮帮我吗)
此包“react-native-vector-icons”已多次添加到您的 build.gradle 文件中。
要解决此问题,只需转至 android>build.gradle 并搜索“react-native-vector-icons”。如果您发现了两次,则删除该行。例如我刚刚注释掉了这个=>
// 申请自:"../../node_modules/react-native-vector-icons/fonts.gradle"
就我而言,我删除了 Android/setting 中的这段代码。gradle
include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')