Running “cordova build android” - unable to find a

2019-01-02 20:02发布

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

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

Here is the output of ./gradlew cdvPrintProps I get 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?

24条回答
牵手、夕阳
2楼-- · 2019-01-02 20:42

Just fix this issue by putting following lines of code in platforms/android/app/build.gradle file, just after buildscript {} block:

configurations.all {
    resolutionStrategy {
            force 'com.android.support:support-v4:27.1.0'
    }
}
查看更多
忆尘夕之涩
3楼-- · 2019-01-02 20:43

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.

查看更多
无与为乐者.
4楼-- · 2019-01-02 20:45

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.

查看更多
大哥的爱人
5楼-- · 2019-01-02 20:46

Just put following in build-extras.gradle

configurations.all {
    resolutionStrategy {
        force 'com.android.support:support-v4:27.1.0'
    }
}
查看更多
零度萤火
6楼-- · 2019-01-02 20:46

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.

查看更多
千与千寻千般痛.
7楼-- · 2019-01-02 20:46

Add the following lines to your platforms/android/build.gradle

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

if still having issue try running this command:

cordova plugin add cordova-android-support-gradle-release --fetch
查看更多
登录 后发表回答