为什么没有任务包装函数工作

时间:2016-10-14 01:34:49

标签: android gradle ionic-framework build.gradle

有很多关于如何修复gradle版本的好建议,但是其中一些已经过时或者我无法找到建议的路径。一个对我有用的解决方案是项目>项目结构>项目> gradle版本

在这里,我可以将其更改为支持的版本,并成功构建项目。

javascript代码中的一个小错误,因此对其进行了更改。 Ionic build android,现在发生错误了。 Minimum supprted Gradle version is 2.14.1. Current version is 2.13.

但是在 project / platforms / android / build.gradle

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

并且从link开始,它表明这是设置gradle包装器的方式。

所以我期望在 project / platforms / android / gradle / wrapper / gradle-wrapper.properties 中拥有distributionUrl=http\://services.gradle.org/distributions/gradle-2.14.1-all.zip,而不是distributionUrl=http\://services.gradle.org/distributions/gradle-2.13-all.zip

无法直接更改此文件 project / platforms / android / gradle / wrapper / gradle-wrapper.properties ,因为每次构建后它都会恢复为{{1} }。

这里发生了什么?无法找到任何可以解释为何继续更改gradle-2.13-all.zip的内容。有人会好心解释这个吗?也许我错过了一些非常愚蠢的东西。谢谢。

我查看的链接

"Gradle Version 2.10 is required." Error

How to update gradle in android studio

ionic build android error when download gradle

gradle code

distributionUrl=http\://services.gradle.org/distributions/gradle-2.13-all.zip

更新

&#39; gradlew包装器抛出错误,因为某些包装器在maven下不存在,而子apply plugin: 'com.android.application' buildscript { repositories { mavenCentral() 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.2.1' } } // Allow plugins to declare Maven dependencies via build-extras.gradle. allprojects { repositories { mavenCentral(); jcenter(); } } task wrapper(type: Wrapper) { gradleVersion = '2.14.1' } // 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-badge/simplelogin777664-badge.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 { 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 { if (cdvMinSdkVersion != null) { minSdkVersion cdvMinSdkVersion } minSdkVersion 16 targetSdkVersion 23 } lintOptions { abortOnError false; } compileSdkVersion 23 buildToolsVersion '21.1.2' if (Boolean.valueOf(cdvBuildMultipleApks)) { productFlavors { armv7 { versionCode defaultConfig.versionCode * 10 + 2 ndk { abiFilters "armeabi-v7a", "" } } x86 { versionCode defaultConfig.versionCode * 10 + 4 ndk { abiFilters "x86", "" } } all { ndk { abiFilters "all", "" } } } } /* ELSE NOTHING! DON'T MESS WITH THE VERSION CODE IF YOU DON'T HAVE TO! 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 { // These must be set or Gradle will complain (even if they are overridden). keyAlias = "" keyPassword = "__unset" // And these must be set to non-empty in order to have the signing step added to the task graph. storeFile = null storePassword = "__unset" } } buildTypes { release { signingConfig signingConfigs.release } } addSigningProps(cdvReleaseSigningPropertiesFile, signingConfigs.release) } if (cdvDebugSigningPropertiesFile) { addSigningProps(cdvDebugSigningPropertiesFile, signingConfigs.debug) } productFlavors { } } dependencies { compile fileTree(include: '*.jar', dir: 'libs') // SUB-PROJECT DEPENDENCIES START debugCompile project(path: "CordovaLib", configuration: "debug") releaseCompile project(path: "CordovaLib", configuration: "release") compile "com.android.support:support-v4:+" // SUB-PROJECT DEPENDENCIES END } def promptForReleaseKeyPassword() { if (!cdvReleaseSigningPropertiesFile) { return; } if ('__unset'.equals(android.signingConfigs.release.storePassword)) { android.signingConfigs.release.storePassword = privateHelpers.promptForPassword('Enter key store password: ') } if ('__unset'.equals(android.signingConfigs.release.keyPassword)) { android.signingConfigs.release.keyPassword = privateHelpers.promptForPassword('Enter key password: '); } } gradle.taskGraph.whenReady { taskGraph -> taskGraph.getAllTasks().each() { task -> if (task.name == 'validateReleaseSigning') { promptForReleaseKeyPassword() } } } def addSigningProps(propsFilePath, signingConfig) { def propsFile = file(propsFilePath) def props = new Properties() propsFile.withReader { reader -> props.load(reader) } def storeFile = new File(props.get('key.store') ?: privateHelpers.ensureValueExists(propsFilePath, props, 'storeFile')) if (!storeFile.isAbsolute()) { storeFile = RelativePath.parse(true, storeFile.toString()).getFile(propsFile.getParentFile()) } if (!storeFile.exists()) { throw new FileNotFoundException('Keystore file does not exist: ' + storeFile.getAbsolutePath()) } signingConfig.keyAlias = props.get('key.alias') ?: privateHelpers.ensureValueExists(propsFilePath, props, 'keyAlias') signingConfig.keyPassword = props.get('keyPassword', props.get('key.alias.password', signingConfig.keyPassword)) signingConfig.storeFile = storeFile signingConfig.storePassword = props.get('storePassword', props.get('key.store.password', signingConfig.storePassword)) def storeType = props.get('storeType', props.get('key.store.type', '')) if (!storeType) { def filename = storeFile.getName().toLowerCase(); if (filename.endsWith('.p12') || filename.endsWith('.pfx')) { storeType = 'pkcs12' } else { storeType = signingConfig.storeType // "jks" } } signingConfig.storeType = storeType } for (def func : cdvPluginPostBuildExtras) { func() } // This can be defined within build-extras.gradle as: // ext.postBuildExtras = { ... code here ... } if (hasProperty('postBuildExtras')) { postBuildExtras() } 使用它来下载build.gradle2.14.1.promThis link will explain it.

发现问题

为什么它不断更改回2.14.1.jar的问题是因为2.13-all.zip而不是var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'http\\://services.gradle.org/distributions/gradle-2.13-all.zip';中的这一行[project name]/platforms/android/cordova/lib/builders/GradleBuilder.js。 (第164行)

5 个答案:

答案 0 :(得分:23)

这里有一个修复 :: 在 Gradle 文件中添加这个

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

答案 1 :(得分:2)

我不完全确定为什么gradle会像这样更新gradle-wrapper.properties文件。但wrapper任务的工作方式意味着您需要调用它来进行更改,因此请尝试以下命令。

project/platforms/android/

  • ./gradlew wrapper - 这会将包装器更新为指定的版本
  • ./gradlew --version由于gradlew使用包装器,如果它尚未在你的机器上缓存,它将下载更新的版本。在顶部,它应该在执行此操作后说2.14.1

答案 2 :(得分:2)

这为我修好了:

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

将此任务添加到build.gradle文件

答案 3 :(得分:0)

为什么它继续改回2.13-all.zip的问题是因为var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'http\\://services.gradle.org/distributions/gradle-2.13-all.zip';而不是[project name]/platforms/android/cordova/lib/builders/GradleBuilder.js中的这一行~/android/lib/GradleBuilder.js。 (第164行)

答案 4 :(得分:0)

如果您使用的是Eclipse,只需更改版本(例如gradleVersion ='4.8')并在“ build-setup”(Gradle Tasks View)下运行“ wrapper”任务,控制台输出将为

EVP_PKEY