Running “cordova build android” - unable to find attribute android:fontVariationSettings and android:ttcIndex

匿名 (未验证) 提交于 2019-12-03 01:58:03

问题:

When I run cordova build android --buildConfig xxxx --release I've the following error:

ERROR: In  FontFamilyFont, unable to find attribute android:fontVariationSettings ERROR: In  FontFamilyFont, unable to find attribute android:ttcIndex 

The strange thing is I use two macOS machines for the compilation, and I've this error only on one of them for the same code.

Here is the output of ./gradlew cdvPrintProps I've on the two machines:

: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 

Below is the list of plugins used:

$ 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" 

How can I fix this problem?

回答1:

Just put following in build-extras.gradle

configurations.all {     resolutionStrategy {         force 'com.android.support:support-v4:27.1.0'     } } 


回答2:

The same error is happening to me. Apparently, a new version of the com.android.support:support-v4 library was released, and the plugin I'm using defines com.android.support:support-v4:+ as dependency in plugin.xml. The + sign means that it will get the latest version (28.0.0), which seems seems to be incompatible with other plugins.

I was able to build a development version by changing all the plugin dependencies from com.android.support:support-v4:+ to com.android.support:support-v4:27.1.0. Also, I executed ionic cordova platform remove android and ionic cordova platform add android. Hope it helps, at least for development.



回答3:

Google released the new version 28.0.0-alpha1 of com.android.support:support-v4 which is adding 2 new attributes(android:fontVariationSettings and android:ttcIndex). Some of the plugins are using the latest android-support libraries which results in unwanted incompatibilities.

Option 1: Install cordova-android-support-gradle-release plugin.

Well documented plugin which "aligns various versions of the Android Support libraries specified by other plugins to a specific version". Tested without any destructive behavior.

cordova plugin add cordova-android-support-gradle-release --fetch 

Read the documentation for a full set of options: Readme

Option 2: Add next code snippet in build.gradle under platforms/android

/**  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' } 

Warning: code in build.gradle will be overwritten if you remove/add the Android platform. If you don't want to use the plugin for some reason or somehow is not working for you, instead create a hook and overwrite the file every time. Check 2nd comment here.

If the problem is persistent you may try:

cordova platform rm android cordova platform add android 

OR

Make sure you don't have a previous version of the app installed on the device you test because you'll receive an ambiguous error when it tries to downgrade the existing version: "INSTALL_FAILED_VERSION_DOWNGRADE" and "UnhandledPromiseRejectionWarning: Unhandled promise rejection"



回答4:

If you really just need a quick fix on that issue to make your build run, you may try adding the following lines into your platforms/android/build.gradle file:

configurations.all {     resolutionStrategy {         force 'com.android.support:support-v4:27.1.0'     } } 

Anyhow, setting the version here is not a sustainable fix.



回答5:

It's strange, but it works when I add the below lines with the same versions.

This is my related lines in the platforms/android/build.gradle file:

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+' } 

In my project, the problem was occurred because of the 'cordova-plugin-crosswalk-webview' plugin.



回答6:

I have the same error but not in cordova build. A new version of the com.android.support:appcompat-v7 and dependencies.But the incompatible version is in the third package that dependent on com.android.support:appcompat-v7.So i can't fixed the third package with @avmatte's solution.

Use @Sai Teja's solution to find incompatible package:

gradlew -q dependencies app:dependencies --configuration debugAndroidTestCompileClasspath 

Then fixed it with:

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}'         ...     } } 

Above code force the dependencies version.



回答7:

I have just fixed this issue by going to the platform/android folder and edited the project.properties) file and replaced com.android.support:support-v4:+ with com.android.support:support-v4:27.1.0.



回答8:

I was facing the same error. Did a complete research in the plugin-directory for com.android.support:support-v4:+ and replaced it with a static version code.

For me, com.android.support:support-v4:23.4.0 worked just fine. There was no need to remove and re-add the android platform then.



回答9:

Some of your libraries should be using

com.android.support:support-v4:+ 

Find which one that is, with

gradlew -q dependencies app:dependencies --configuration debugAndroidTestCompileClasspath 

And add that library as a module if it is not using a specific version in it's latest update (Also raise an issue in that library! ;) )

Thanks to @avmatte!



回答10:

Here's an easy way to fix it that will persist when the platform directory is rebuilt and there's no need to go through all your plugins to try and find a culprit. Create a file build-extras.gradle with these contents:

configurations.all {     resolutionStrategy {         force 'com.android.support:support-v4:27.1.0'     } } 

Then create the file after_platform_add/010_copy_build_extras.js with the following contents:

#!/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}`)); } 

Now recreate the android platform and it will use the pinned support library.



回答11:

I was having the same problem out of the blue yesterday. It started randomly, but from reading around, it looks like it is to do with an update as mentioned above by @cpro90. However, I tried and could not find where to make the necessary manual change.

Eventually I identified that the problem was being caused by my cordova-plugin-crosswalk-webview plugin. On GitHub, I found the issue on the plugin repro this morning, and it had over 520 views by lunch.

@UNUMObile suggested the following in the build.gradle file to force an earlier version globally:

configurations.all {     resolutionStrategy.force 'com.android.support:support-v4:24.0.0' } 

This worked immediately for me and may help others with other plugins that also have had their dependency on 'com.android.support:support-4:

I hope this helps someone move forward.



回答12:

It's a duplicate entry in values.xml in a folder called support-compat-28.0.0-alpha1.aar.

You'll find this file on Windows at \users\YOURUSERID\.gradle\caches\transforms-1\files-1.1

Once inside that folder you have to go some levels deeper to values.xml.

In that file, search for an element

Another aproach with same solution is create a hook. It's persistent (after platform reinstall), you can commit it and it don't require re-adding platform.

%project%\scripts\android\android-support-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');   } }; 

Init hook in config

%project%\config.xml

...    ... 

Install fs dependency to your project:

npm i fs --save-dev

Run build:

cordova build android



回答14:

In your build.gradle file add

configurations.all {     resolutionStrategy {         force 'com.android.support:support-v4:27.1.0'     } } 

And in your project.properties file change cordova.system.library.3 to cordova.system.library.3=com.android.support:support-v13:27.+.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!