当我运行cordova build android --buildConfig xxxx --release
时,
我收到以下错误:
ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:fontVariationSettings
ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:ttcIndex
奇怪的是我使用两台macOS机器进行编译,我只在其中一台机器上使用相同的代码才会出现此错误。
以下是我在两台机器上的./gradlew cdvPrintProps
输出:
:cdvPrintProps
cdvCompileSdkVersion=26
cdvBuildToolsVersion=27.0.3
cdvVersionCode=null
cdvMinSdkVersion=21
cdvBuildMultipleApks=true
cdvReleaseSigningPropertiesFile=release-signing.properties
cdvDebugSigningPropertiesFile=null
cdvBuildArch=null
computedVersionCode=152045989
computedArmv7VersionCode=1520459892
computedX86VersionCode=1520459894
以下是使用的插件列表:
$ cordova plugins list
cordova-custom-config 5.0.2 "cordova-custom-config"
cordova-fabric-plugin 1.1.10 "cordova-fabric-plugin"
cordova-open-native-settings 1.5.0 "Native settings"
cordova-plugin-app-event 1.2.1 "Application Events"
cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-camera 2.4.1 "Camera"
cordova-plugin-compat 1.2.0 "Compat"
cordova-plugin-console 1.1.0 "Console"
cordova-plugin-crosswalk-webview 2.4.0 "Crosswalk WebView Engine"
cordova-plugin-datepicker 0.9.2 "DatePicker"
cordova-plugin-device 2.0.1 "Device"
cordova-plugin-email 1.2.7 "EmailComposer"
cordova-plugin-file 4.3.3 "File"
cordova-plugin-file-transfer 1.6.3 "File Transfer"
cordova-plugin-inappbrowser 1.7.2 "InAppBrowser"
cordova-plugin-network-information 1.3.4 "Network Information"
cordova-plugin-secure-storage 2.6.8 "SecureStorage"
cordova-plugin-splashscreen 4.1.0 "Splashscreen"
cordova-plugin-statusbar 2.4.1 "StatusBar"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova.plugins.diagnostic 3.9.2 "Diagnostic"
de.appplant.cordova.plugin.local-notification 0.8.5 "LocalNotification"
ionic-plugin-keyboard 2.2.1 "Keyboard"
如何解决此问题?
答案 0 :(得分:103)
只需将以下内容放入 build-extras.gradle
即可configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}
}
答案 1 :(得分:78)
Google发布了 com.android.support:support-v4 的新版 28.0.0-alpha1 ,它增加了2个新属性(android:fontVariationSettings和android: ttcIndex)。 一些插件使用最新的android支持库,导致不必要的兼容性。
选项1: 安装 cordova-android-support-gradle-release 插件。
文档齐全的插件“将其他插件指定的Android支持库的各种版本与特定版本对齐”。测试时没有任何破坏性行为。
cordova plugin add cordova-android-support-gradle-release --fetch
阅读文档以获取一整套选项:Readme
选项2 : 在 platforms / android
下的 build.gradle 中添加下一个代码段/**
IMPORTANT - Manually added
Problem: 8 March 2018 - Google released version support-v4:28.0.0-alpha1
which breaks the project with following error: unable to find attribute
android:fontVariationSettings and android:ttcIndex
Effect: Force a specific version of the library
*/
configurations.all {
resolutionStrategy.force 'com.android.support:support-v4:27.1.0'
}
如果您删除/添加Android平台,警告 build.gradle 中的代码将被覆盖。如果您由于某种原因不想使用该插件或以某种方式不适合您,而是每次都创建一个钩子并覆盖该文件。检查第二条评论here。
如果问题持续存在,您可以尝试:
cordova platform rm android
cordova platform add android
或强>
确保您在测试的设备上没有安装以前版本的应用,因为在尝试降级现有版本时会收到一个模棱两可的错误:“INSTALL_FAILED_VERSION_DOWNGRADE” “UnhandledPromiseRejectionWarning:未处理的承诺拒绝”
答案 2 :(得分:31)
同样的错误发生在我身上。显然,我发布了com.android.support:support-v4
库的新版本,我使用的插件将com.android.support:support-v4:+
定义为plugin.xml
中的依赖项。 +
符号表示它将获得最新版本(28.0.0),这似乎与其他插件不兼容。
我能够通过将所有插件依赖项从com.android.support:support-v4:+
更改为com.android.support:support-v4:27.1.0
来构建开发版本。另外,我执行了ionic cordova platform remove android
和ionic cordova platform add android
。希望它有所帮助,至少对发展而言。
答案 3 :(得分:26)
我刚刚修改此问题,方法是转到platform / android文件夹并编辑project.properties
)文件,并将com.android.support:support-v4:+
替换为com.android.support:support-v4:27.1.0
。
答案 4 :(得分:21)
如果您真的需要快速修复该问题以使您的构建运行,您可以尝试将以下行添加到您的platforms / android / build.gradle文件中:
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}
}
无论如何,在这里设置版本不是一个可持续的解决方案。
答案 5 :(得分:15)
这很奇怪,但是当我添加相同版本的以下行时它会起作用。
这是platforms/android/build.gradle
文件中的相关行:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// SUB-PROJECT DEPENDENCIES START
debugCompile(project(path: "CordovaLib", configuration: "debug"))
releaseCompile(project(path: "CordovaLib", configuration: "release"))
compile "com.android.support:support-v4:26.+"
compile "com.android.support:appcompat-v7:26.+"
// SUB-PROJECT DEPENDENCIES END
}
// ADDED THESE LINES
configurations.all {
resolutionStrategy.force 'com.android.support:support-v4:26+'
}
在我的项目中,问题出现是因为'cordova-plugin-crosswalk-webview'插件。
答案 6 :(得分:8)
我有同样的错误,但没有在cordova构建中。 com.android.support:appcompat-v7
和依赖项的新版本。但是不兼容的版本位于依赖于com.android.support:appcompat-v7
的第三个包中。所以我无法使用@avmatte的解决方案修复第三个包。
使用@ Sai Teja的解决方案来查找不兼容的包:
gradlew -q dependencies app:dependencies --configuration debugAndroidTestCompileClasspath
然后用:
修复它configurations.all {
resolutionStrategy {
force 'com.android.support:support-compat:{the_same_version}'
force 'com.android.support:appcompat-v7:{the_same_version}'
force 'com.android.support:support-core-utils:{the_same_version}'
force 'com.android.support:support-core-ui:{the_same_version}'
force 'com.android.support:support-fragment:{the_same_version}'
force 'com.android.support:support-annotations:{the_same_version}'
...
}
}
上面的代码强制依赖版本。
答案 7 :(得分:8)
我遇到了同样的错误。对 com.android.support:support-v4:+ 的插件目录进行了全面研究,并将其替换为静态版本代码。
对我来说, com.android.support:support-v4:23.4.0 工作正常。那时就没有必要删除并重新添加android平台了。
答案 8 :(得分:8)
这是一种简单的方法来修复它,当平台目录重建时,它将持续存在,并且无需通过所有插件来尝试查找罪魁祸首。使用以下内容创建文件build-extras.gradle
:
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}
}
然后使用以下内容创建文件after_platform_add/010_copy_build_extras.js
:
#!/usr/bin/env node
var fs = require('fs');
var rootdir = process.argv[2];
var android_dir = `${rootdir}/platforms/android`;
var gradle_filename = 'build-extras.gradle';
var gradle_file = `${rootdir}/${gradle_filename}`;
if (fs.existsSync(android_dir) && fs.existsSync(gradle_file)) {
fs.createReadStream(gradle_file)
.pipe(fs.createWriteStream(`${android_dir}/${gradle_filename}`));
}
现在重新创建Android平台,它将使用固定支持库。
答案 9 :(得分:4)
您的某些图书馆应该使用
com.android.support:support-v4:+
使用
查找哪一个gradlew -q dependencies app:dependencies --configuration debugAndroidTestCompileClasspath
如果该库未在其最新更新中使用特定版本,则将该库添加为模块(同时在该库中引发问题!))
感谢@avmatte!
答案 10 :(得分:4)
我昨天遇到了同样的问题。它是随机开始的,但从阅读开始,看起来它与@ cpro90上面提到的更新有关。但是,我试过并找不到在哪里进行必要的手动更改。
最终我发现问题是由我的cordova-plugin-crosswalk-webview插件引起的。在GitHub上,今天早上我在插件repro上找到the issue,午餐时它有超过520个观看次数。
@UNUMObile在build.gradle
文件中建议以下内容强制全局使用早期版本:
configurations.all {
resolutionStrategy.force 'com.android.support:support-v4:24.0.0'
}
这对我来说很有效,并且可以帮助其他插件,这些插件也依赖于'com.android.support:support-4:<28。新版本28似乎是个问题。
我希望这可以帮助某些人前进。
答案 11 :(得分:4)
将以下几行添加到您的platform / android / build.gradle
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}
}
如果仍然有问题,请尝试运行以下命令:
cordova plugin add cordova-android-support-gradle-release --fetch
答案 12 :(得分:3)
在build.gradle
文件中添加
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}
}
在project.properties
文件中将cordova.system.library.3
更改为cordova.system.library.3=com.android.support:support-v13:27.+
。
答案 13 :(得分:2)
对于 Phonegap Build 用户,如评论中提到的@catu,您可以尝试this plugin,其目的是,以防止因包含不同版本的支持库而导致的构建失败
答案 14 :(得分:1)
只需修改此问题,方法是将以下几行代码放在platforms / android / app / build.gradle文件中,就在buildscript {}块之后:
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}
}
答案 15 :(得分:1)
安装cordova-plugin-file-opener2插件后,我遇到了同样的问题。它在执行以下操作后已保存: 选项1:安装cordova-android-support-gradle-release插件。 cordova插件添加cordova-android-support-gradle-release --fetch
答案 16 :(得分:0)
使用相同解决方案的另一个方法是创建一个钩子。它是持久的(在平台重新安装之后),你可以提交它并且它不需要重新添加平台。
%项目%\脚本\机器人\机器人支撑-version.js
#!/usr/bin/env node
var fs = require('fs');
function replace_strings_in_file(filename, replacementsObject) {
if (fs.existsSync(filename)) {
var data = fs.readFileSync(filename, 'utf8');
Object.keys(replacementsObject).forEach(function (to_replace) {
var replace_with = replacementsObject[to_replace];
data = data.replace(to_replace, replace_with);
});
console.log(data);
fs.writeFileSync(filename, data, 'utf8');
} else {
console.log('file not found');
}
}
module.exports = function (context) {
var rootdir = process.argv[2];
if (rootdir) {
replace_strings_in_file("platforms/android/project.properties", {'com.android.support:support-v4:+': 'com.android.support:support-v4:27.1.0'});
console.log('com.android.support version fix');
}
};
配置
中的初始化挂钩%项目%\ config.xml中
...
<platform name="android">
<hook src="scripts/android/android-support-version.js" type="before_build" />
...
将fs依赖项安装到您的项目中:
npm i fs --save-dev
运行构建:
cordova build android
答案 17 :(得分:0)
超级简单且正确解决问题的方法!
只需更新sdk并添加最新的2版android ...并重新启动计算机!完成......
现在我们有时间谈论汽车和运动......
答案 18 :(得分:0)
我遇到了同样的问题,并且没有一个给定的解决方案适合我。安装最新版本的Android SDK Build-tools(27.0.3)解决了我的问题。
答案 19 :(得分:0)
这是因为compat插件。 如果你有旧版本(小于 1.2.0 )并设置 cordova-android@6.3.0
,请删除该插件cordova插件rm cordova-plugin-compat --force
cordova插件添加cordova-plugin-compat@1.2.0
cordova platform rm android
离子cordova平台添加android@6.3.0
在我的案子中工作。谢谢:))
答案 20 :(得分:0)
更新@Brad Pitcher的答案:
fid=open("w&c","w")
for x in range (0, 2):
w=input("Enter a word: ")
fid.write(w+'\n')
c1=input("Enter a clue: ")
fid.write(c1+'\n')
c2=input("Enter a clue: ")
fid.write(c2+'\n')
c3=input("Enter a clue: ")
fid.write(c3+'\n')
fid.close()
hooks/copy_build_extras.js
#!/usr/bin/env node
var fs = require('fs');
module.exports = function (context) {
var rootdir = context.opts.projectRoot;
var android_dir = `${rootdir}/platforms/android`;
var gradle_filename = 'build-extras.gradle';
var gradle_file = `${rootdir}/${gradle_filename}`;
if (fs.existsSync(android_dir) && fs.existsSync(gradle_file)) {
fs.createReadStream(gradle_file)
.pipe(fs.createWriteStream(`${android_dir}/${gradle_filename}`));
}
};
config.xml
根目录中的 <platform name="android">
<allow-intent href="market:*" />
<hook src="hooks/copy_build_extras.js" type="before_build" />
</platform>
build-extras.gradle
答案 21 :(得分:0)
如果您使用的是离子型,并且出现此错误,请执行以下操作解决该问题:
-cordova platform rm android
-cordova platform add android
可能是一种解决方案
答案 22 :(得分:0)
我正在用本机反应遇到此问题,这是由我的android/app/build.gradle
中的以下几行引起的:
implementation ("com.google.android.gms:play-services-base:+") {
force = true;
}
implementation ("com.google.android.gms:play-services-maps:+") {
force = true;
}
等...
显然,此+解决了新的17.0.0版本,这破坏了我的构建。
将+更改为16.0.0(或对于play-services-base为16.0.1)解决了我的问题
答案 23 :(得分:0)
我在Ionic论坛上找到了该解决方案,这是唯一对我有用的解决方案:
运行:
ionic cordova平台rm android
运行:
ionic cordova平台添加android@8.0.0
运行:
ionic cordova插件添加cordova-plugin-androidx
运行:
ionic cordova插件添加cordova-plugin-androidx-adapter
确保您的gradle.properties具有:
cdvMinSdkVersion = 19
确保您的build.gradle具有:
project.ext { defaultBuildToolsVersion="28.0.3" //String
defaultMinSdkVersion=19 //Integer - Minimum requirement is Android 4.4
defaultTargetSdkVersion=28 //Integer - We ALWAYS target the latest by default
defaultCompileSdkVersion=28 //Integer - We ALWAYS compile with the latest by default }
确保您的config.xml具有:
<preference name="android-minSdkVersion" value="19" />
也可以在stackoverflow答案中处理: https://stackoverflow.com/a/56656680/839691
答案 24 :(得分:0)
这个问题已经使我丧命了一个星期。
我最终以android@6.4.0
我通过更改来更改了android/project.properties
#cordova.system.library.3=com.google.android.gms:play-services-analytics:+
cordova.system.library.3=com.google.android.gms:play-services-analytics:15+
这种改变最终使我摆脱了ttcIndex错误消息之深渊。
然后我收到此错误
com.android.builder.dexing.DexArchiveBuilderException:
com.android.builder.dexing.DexArchiveBuilderException
该错误显然是由于Java版本问题引起的。然后,我通过以下更改更改了android/build.gradle
compileOptions {
#sourceCompatibility JavaVersion.VERSION_1_6
#targetCompatibility JavaVersion.VERSION_1_6
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
还请注意,我确实安装了cordova-android-support-gradle-release
插件,但是不知道是否需要它。
答案 25 :(得分:-1)
它是名为support-compat-28.0.0-alpha1.aar
的文件夹中values.xml中的重复条目。
您可以在\users\YOURUSERID\.gradle\caches\transforms-1\files-1.1
进入该文件夹后,您必须更深入 values.xml 。
在该文件中,搜索元素<declare-styleable name="FontFamilyFont>
。
在该元素中,删除其中包含android:
的四行。
在我做出改变之后,我可以毫无错误地再次构建。