gpt4 book ai didi

带有 Gradle 和 Proguard 的 Android

转载 作者:行者123 更新时间:2023-11-29 15:18:24 26 4
gpt4 key购买 nike

我刚刚使用 Gradle 创建了一个新的 Android Library 项目,并希望通过 Proguard 优化和混淆代码。

这是 build.gradle 文件中的 android 部分:

android {
compileSdkVersion 19
buildToolsVersion "19.0.1"

defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.txt'
}
}

当我从终端运行 gradle build 命令时,它在 :library:proguardRelease 失败并显示消息:

* What went wrong:
Execution failed for task ':library:proguardRelease'.
> java.io.IOException: The output jar is empty. Did you specify the proper '-keep' options?

有人知道这是为什么吗?

Gradle 1.10虚拟机 1.6.0_65程序 4.10

最佳答案

在执行 gradlew assembleRelease 时,以下 build.gradle 文件适用于 Proguard。

请注意,它被设置为从配置文件中读取发布 keystore 信息(我已经在项目中包含了调试 key 证书,因为 Debug模式下 Maps API v2 需要它),以及来自命令行的密码:

apply plugin: 'android'

android {
compileSdkVersion 19
buildToolsVersion "19.0.0"

defaultConfig {
minSdkVersion 8
targetSdkVersion 19
}

if (project.hasProperty("secure.properties")
&& new File(project.property("secure.properties")).exists()) {

Properties props = new Properties()
props.load(new FileInputStream(file(project.property("secure.properties"))))

signingConfigs {
debug {
storeFile file("gpstest.debug.keystore")
}

release {
storeFile file(props['key.store'])
keyAlias props['key.alias']
storePassword "askmelater"
keyPassword "askmelater"
}
}
} else {
signingConfigs {
debug {
storeFile file("gpstest.debug.keystore")
}

release {
// Nothing here
}
}
}

buildTypes {
release {
runProguard true
proguardFile 'proguard.cfg'
signingConfig signingConfigs.release
}
}
}

task askForPasswords << {
// Must create String because System.readPassword() returns char[]
// (and assigning that below fails silently)
def storePw = new String(System.console().readPassword("\nKeystore password: "))
def keyPw = new String(System.console().readPassword("Key password: "))

android.signingConfigs.release.storePassword = storePw
android.signingConfigs.release.keyPassword = keyPw
}

tasks.whenTaskAdded { theTask ->
if (theTask.name.equals("packageRelease")) {
theTask.dependsOn "askForPasswords"
}
}

dependencies {
compile project(':ShowcaseViewLibrary')
compile 'com.google.android.gms:play-services:3.2.65'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
compile 'org.jraf:android-switch-backport:1.2'
compile 'com.google.maps.android:android-maps-utils:0.2.1'
}

以下是设置配置文件以读取 keystore 信息的说明:

To build a release build, you need to create a "gradle.properties" file that points to a "secure.properties" file, and a "secure.properties" file that points to your keystore and alias. The gradlew assembleRelease command will prompt for your keystore passphrase.

The "gradle.properties" file is located in the GPSTest directory and has the contents:

secure.properties=<full_path_to_secure_properties_file>

The "secure.properties" file (in the location specified in gradle.properties) has the contents:

key.store=<full_path_to_keystore_file>

key.alias=<key_alias_name>

Note that the paths in these files always use the Unix path separator /, even on Windows. If you use the Windows path separator \ you will get the error No value has been specified for property 'signingConfig.keyAlias'.

如果您想自己克隆和测试,这里是 Github 上文件/项目的路径: https://github.com/barbeau/gpstest/blob/master/GPSTest/build.gradle

proguard.cfg 也在 GPSTest 子目录中(与 build.gradle 相同的目录): https://github.com/barbeau/gpstest/blob/master/GPSTest/proguard.cfg

关于带有 Gradle 和 Proguard 的 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21691678/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com