cordova问题

2017-09-07  本文已影响323人  8321

问题

项目为Android Cordova,在没有任何改动情况下build报错,在github和starkoverflow发现事Cordova官方插件服务器挂了,无语森。

Error:A problem occurred configuring root project 'android'.
> Could not resolve all dependencies for configuration ':_prodDebugApkCopy'.
   > Could not resolve org.xwalk:xwalk_core_library:17+.
     Required by:
         project :
      > Could not resolve org.xwalk:xwalk_core_library:17+.
         > Failed to list versions for org.xwalk:xwalk_core_library.
            > Unable to load Maven meta-data from https://download.01.org/crosswalk/releases/crosswalk/android/maven2/org/xwalk/xwalk_core_library/maven-metadata.xml.
               > Could not GET 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2/org/xwalk/xwalk_core_library/maven-metadata.xml'. Received status code 503 from server: Service Unavailable

在官方不靠谱无回应的情况下,终于在GitHub上找到了解决方法

This can solve the issue for latest crosswalk version.
Open platforms\android\cordova-plugin-crosswalk-webview\eqp-xwalk.gradle
change this:

dependencies {
compile xwalkSpec
}

to this one:

dependencies {
compile 'org.xwalk:xwalk_core_library:23.53.589.4' //xwalkSpec
}

烦恼会解决烦恼,bug会解决bug,在clean之后,又发生的下面的错误

5-11:41 Error:
uses-sdk:minSdkVersion 14 cannot be smaller than version 16 declared in library [org.xwalk:xwalk_core_library:23.53.589.4] /Users/eminem/.android/build-cache/86c2a1a3bd3e937850104f58d37ae77b32050429/output/AndroidManifest.xml
    Suggestion: use tools:overrideLibrary="org.xwalk.core" to force usage
    
See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.
:processSitDebugManifest FAILED
FAILURE: Build failed with an exception.

之后在知乎上找到症结所在,但由于项目是Cordova,build.gradle比较特殊,如下:

// GENERATED FILE! DO NOT EDIT!

apply plugin: 'android'

buildscript {
    repositories {

        jcenter()
    }

    // Switch the Android Gradle plugin version requirement depending on the
    // installed version of Gradle. This dependency is documented at
    // http://tools.android.com/tech-docs/new-build-system/version-compatibility
    // and https://issues.apache.org/jira/browse/CB-8143
    dependencies {
//        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.android.tools.build:gradle:2.3.0'
    }
}

// Allow plugins to declare Maven dependencies via build-extras.gradle.
repositories {
    flatDir {
        dirs 'libs'
    }
    mavenCentral()
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.8'
}

// Configuration properties. Set these via environment variables, build-extras.gradle, or gradle.properties.
// Refer to: http://www.gradle.org/docs/current/userguide/tutorial_this_and_that.html
ext {
    apply from: 'CordovaLib/cordova.gradle'
    // The value for android.compileSdkVersion.
    if (!project.hasProperty('cdvCompileSdkVersion')) {
        cdvCompileSdkVersion = null;
    }
    // The value for android.buildToolsVersion.
    if (!project.hasProperty('cdvBuildToolsVersion')) {
        cdvBuildToolsVersion = null;
    }
    // Sets the versionCode to the given value.
    if (!project.hasProperty('cdvVersionCode')) {
        cdvVersionCode = null
    }
    // Sets the minSdkVersion to the given value.
    if (!project.hasProperty('cdvMinSdkVersion')) {
        cdvMinSdkVersion = null
    }
    // Whether to build architecture-specific APKs.
    if (!project.hasProperty('cdvBuildMultipleApks')) {
        cdvBuildMultipleApks = null
    }
    // .properties files to use for release signing.
    if (!project.hasProperty('cdvReleaseSigningPropertiesFile')) {
        cdvReleaseSigningPropertiesFile = null
    }
    // .properties files to use for debug signing.
    if (!project.hasProperty('cdvDebugSigningPropertiesFile')) {
        cdvDebugSigningPropertiesFile = null
    }
    // Set by build.js script.
    if (!project.hasProperty('cdvBuildArch')) {
        cdvBuildArch = null
    }

    // Plugin gradle extensions can append to this to have code run at the end.
    cdvPluginPostBuildExtras = []
}

// PLUGIN GRADLE EXTENSIONS START
apply from: "cordova-plugin-crosswalk-webview/portal-xwalk.gradle"
// PLUGIN GRADLE EXTENSIONS END

def hasBuildExtras = file('build-extras.gradle').exists()
if (hasBuildExtras) {
    apply from: 'build-extras.gradle'
}

// Set property defaults after extension .gradle files.
if (ext.cdvCompileSdkVersion == null) {
    ext.cdvCompileSdkVersion = privateHelpers.getProjectTarget()
}
if (ext.cdvBuildToolsVersion == null) {
    ext.cdvBuildToolsVersion = privateHelpers.findLatestInstalledBuildTools()
}
if (ext.cdvDebugSigningPropertiesFile == null && file('debug-signing.properties').exists()) {
    ext.cdvDebugSigningPropertiesFile = 'debug-signing.properties'
}
if (ext.cdvReleaseSigningPropertiesFile == null && file('release-signing.properties').exists()) {
    ext.cdvReleaseSigningPropertiesFile = 'release-signing.properties'
}

// Cast to appropriate types.
ext.cdvBuildMultipleApks = cdvBuildMultipleApks == null ? false : cdvBuildMultipleApks.toBoolean();
ext.cdvMinSdkVersion = cdvMinSdkVersion == null ? null : Integer.parseInt('' + cdvMinSdkVersion)
ext.cdvVersionCode = cdvVersionCode == null ? null : Integer.parseInt('' + cdvVersionCode)

def computeBuildTargetName(debugBuild) {
    def ret = 'assemble'
    if (cdvBuildMultipleApks && cdvBuildArch) {
        def arch = cdvBuildArch == 'arm' ? 'armv7' : cdvBuildArch
        ret += '' + arch.toUpperCase().charAt(0) + arch.substring(1);
    }
    return ret + (debugBuild ? 'Debug' : 'Release')
}

// Make cdvBuild a task that depends on the debug/arch-sepecific task.
task cdvBuildDebug
cdvBuildDebug.dependsOn {
    return computeBuildTargetName(true)
}

task cdvBuildRelease
cdvBuildRelease.dependsOn {
    return computeBuildTargetName(false)
}

task cdvPrintProps << {
    println('cdvCompileSdkVersion=' + cdvCompileSdkVersion)
    println('cdvBuildToolsVersion=' + cdvBuildToolsVersion)
    println('cdvVersionCode=' + cdvVersionCode)
    println('cdvMinSdkVersion=' + cdvMinSdkVersion)
    println('cdvBuildMultipleApks=' + cdvBuildMultipleApks)
    println('cdvReleaseSigningPropertiesFile=' + cdvReleaseSigningPropertiesFile)
    println('cdvDebugSigningPropertiesFile=' + cdvDebugSigningPropertiesFile)
    println('cdvBuildArch=' + cdvBuildArch)
    println('computedVersionCode=' + android.defaultConfig.versionCode)
    android.productFlavors.each { flavor ->
        println('computed' + flavor.name.capitalize() + 'VersionCode=' + flavor.versionCode)
    }
}

android {
//    compileSdkVersion 25
//    buildToolsVersion '25.0.2'

    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }
    lintOptions {
        abortOnError false
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
        }
    }
    defaultConfig {
        versionCode cdvVersionCode ?: Integer.parseInt("" + privateHelpers.extractIntFromManifest("versionCode") + "0")
        applicationId privateHelpers.extractStringFromManifest("package")

        if (cdvMinSdkVersion != null) {
            minSdkVersion cdvMinSdkVersion
        }
        multiDexEnabled true;
        ndk {
            // 设置支持的 SO 库构架,注意这里要根据你的实际情况来设置
            abiFilters 'armeabi'
        }
    }
    lintOptions {
        abortOnError false;
    }
    compileSdkVersion cdvCompileSdkVersion
    buildToolsVersion cdvBuildToolsVersion
    if (Boolean.valueOf(cdvBuildMultipleApks)) {
        productFlavors {
            armv7 {
                versionCode defaultConfig.versionCode + 2
                ndk {
                    abiFilters "armeabi-v7a", ""
                }
            }
            x86 {
                versionCode defaultConfig.versionCode + 4
                ndk {
                    abiFilters "x86", ""
                }
            }
            all {
                ndk {
                    abiFilters "all", ""
                }
            }
        }
    } else if (!cdvVersionCode) {
        def minSdkVersion = cdvMinSdkVersion ?: privateHelpers.extractIntFromManifest("minSdkVersion")
        // Vary versionCode by the two most common API levels:
        // 14 is ICS, which is the lowest API level for many apps.
        // 20 is Lollipop, which is the lowest API level for the updatable system webview.
        if (minSdkVersion >= 20) {
            defaultConfig.versionCode += 9
        } else if (minSdkVersion >= 14) {
            defaultConfig.versionCode += 8
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    if (cdvReleaseSigningPropertiesFile) {
        signingConfigs {
            release {
           
            }
        }
        buildTypes {
            release {
                minifyEnabled  true //是否混淆
                zipAlignEnabled true // zip对齐优化
                shrinkResources true // 移除不必要的资源
//              buildConfigField "boolean", "LOG_DEBUG", "false"// 不显示Log
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard.cfg'
//              proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
                signingConfig signingConfigs.release

                //自动重命名
                android.applicationVariants.all { variant ->
                    variant.outputs.each { output ->
                        output.outputFile = new File(output.outputFile.parent,
                                "HRBank_" + productFlavors[0].name + "_" + buildType.name +
                                        ".apk");
                    }
                }

            }
        }

        productFlavors {

            tencent {}
            uat {}
            sit {}
            prod {}
            productFlavors.all { flavors ->
                flavors.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
            }
        }
        addSigningProps(cdvReleaseSigningPropertiesFile, signingConfigs.release)
    }
    if (cdvDebugSigningPropertiesFile) {
        addSigningProps(cdvDebugSigningPropertiesFile, signingConfigs.debug)
    }

    dexOptions {
        javaMaxHeapSize "8g"
        preDexLibraries = false
    }

}

不是太明白,多方查找问题解决,需要认真研究下Cordova build的配置信息,设置cdvMinSdkVersion=16

  // Sets the minSdkVersion to the given value.
    if (!project.hasProperty('cdvMinSdkVersion')) {
        cdvMinSdkVersion = null
    }

参考

Manifest merger failed with multiple errors, see ?
cordova build android get error
Cordova开发平台配置--Android
使用Android Studio构建Cordova项目

上一篇 下一篇

猜你喜欢

热点阅读