Running "corova build android" - could not find android attribute: fontVariationSettings and android: ttcIndex

When I run cordova build android --buildConfig xxxx --release, I get the following error:

ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:fontVariationSettings
ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:ttcIndex

It is strange that I use two macOS machines to compile, and I get this error on only one of them for the same code.

Here is the result ./gradlew cdvPrintPropsthat I get on 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

The following is a 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?

+98
source share
26 answers

Just put the following in build-extras.gradle

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

Google 28.0.0-alpha1 com.android.support:support-v4, 2 (android: fontVariationSettings android: ttcIndex). Android, .

1: cordova-android-support- gradle -release.

, " Android, , ". - .

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

: Readme

2: 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'
}

: build.gradle , / Android. - - , . 2- .

, :

cordova platform rm android
cordova platform add android

, ​​ , : "INSTALL_FAILED_VERSION_DOWNGRADE" "UnhandledPromiseRejectionWarning: "

+81

. -, 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. , , , .

+31

, /android project.properties) com.android.support:support-v4:+ com.android.support:support-v4:27.1.0.

+26

, , platform/android/build.gradle:

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

, .

+21

, , .

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

+15

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

.

+8

. com.android.support:support-v4: + .

com.android.support:support-v4:23.4.0 . Android.

+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, .

+8

com.android.support:support-v4:+

, ,

gradlew -q dependencies app:dependencies --configuration debugAndroidTestCompileClasspath

, ( !))

@avmatte!

+5

. , - , , , , @cpro90. , .

, ---webview-. GitHub , , 520 .

@UNUMObile build.gradle :

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

, "com.android.support:support-4:<28. 28, , .

, - .

+4

Kotlin:

, , support-v4 , , , ktx.

, 1.0.0-alpha1 ktx, ; , 0.3, .

+4

/android/build.gradle

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

, :

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

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.+.

+3

Phonegap Build, @catu, , , .

+2

, platform/android/app/build.gradle buildscript {}:

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

cordova-plugin-file-opener2. : 1: cordova-android-support-gradle-release. Cordova Cordova-Android-Support-Gradle- --fetch

+1

- . ( ), , .

% %\Scripts\Android\--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 fs --save-dev

:

0

!

SDK Android 2... ! ...

...

0

, . Android SDK Build-tools (27.0.3) .

0

Compat. , ( 1.2.0) cordova-android@6.3.0

-- --force

Cordova Cordova-plugin-compat@1.2.0

Cordova Android@6.3.0

. :)

0

@Brad Pitcher:

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 build-extras.gradle

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

android/app/build.gradle , 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 ( 16.0.1 play-services-base)

0

Ionic Forum, , :

:

:

Cordova Android@8.0.0

:

--androidx

:

Cordova Cordova--Androidroid-

, 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" />

: https://forum.ionicframework.com/t/firebase-app-unable-to-compile-on-android-with-aapt-error/166564/7

stackoverflow: fooobar.com/questions/17861467/...

0

values.xml support-compat-28.0.0-alpha1.aar.

Windows \users\YOURUSERID\.gradle\caches\transforms-1\files-1.1

Once inside this folder you need to go through several levels to values.xml .

Find the item in this file <declare-styleable name="FontFamilyFont>.

In this element, delete four lines with android:.

After I made this change, I can build again without errors.

-1
source

If you use ionic and get this error, resolve it by following these steps:

-cordova platform rm android
-cordova platform add android

This may be a possible solution.

-2
source

All Articles