我正在使用Android Studio 1.2.2并尝试使用proguard设置生成APK。但我不能这样做并得到以下错误信息。
"任务执行失败':packageRelease'。
无法计算/Users/Documents/projectX/app/build/intermediates/classes-proguard/release/classes.jar的散列"
proguard设置很简单。
-dontshrink
-dontoptimize
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
gradle文件位于下方。
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion "Google Inc.:Google APIs:22"
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.bientus.cirque.sansotong"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
// multiDexEnabled true
}
buildTypes {
debug {
debuggable true
}
release {
minifyEnabled true
//proguardFiles 'proguard-project.txt', 'proguard.cfg'
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt', 'proguard.cfg'
proguardFiles 'proguard-project.txt'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile "com.google.android.gms:play-services:7.5.0"
// compile 'com.android.support:multidex:1.0.0'
}
buildscript {
repositories {
// mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.google.gms:google-services:1.3.0-beta1'
}
}
任何人都可以提出任何想法或想法吗? 非常感谢你!
答案 0 :(得分:10)
在' proguard-project.txt'中设置以下内容后,它起了作用。 显然应该为这个文件设置gradle。
-dontwarn android.support.v7.**
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
答案 1 :(得分:4)
查看您的构建输出。你可能会在那里有proguard警告,比如你有两个共享某个类的库(具有潜在的不同版本)。
这可能会阻止proguard计算哈希值。
我在构建中同时使用openIAB和opfIAB(都使用亚马逊和谷歌IAB)时遇到了同样的问题。删除其中一个库解决了我的问题
答案 2 :(得分:3)
OK!它很容易!只需按照以下步骤操作: build.gradle:minifyEnabled false - > minifyEnabled是的 proguard-rules.pro: 你必须添加你在项目中使用的第三个库,如piccaso等。 如果你在android studio中这样做,它会拒绝这些文件。
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Test</title>
<link href="static/css/bootstrap.min.css" rel="stylesheet">
<link href="static/css/sb-admin.css" rel="stylesheet">
<link href="static/css/bootstrap-multiselect.css" rel="stylesheet">
<link href="static/lib/css/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>
</head>
<body onload = onLoading()>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">BNG Subscriber Analytics</a>
</div>
</nav>
<div class="row">
<div class="col-sm-3 col-md-6 col-lg-4" id="i1"></div>
<div class="col-sm-3 col-md-6 col-lg-4" id="i2"></div>
<div class="col-sm-3 col-md-6 col-lg-4" id="i3"></div>
<div class="col-sm-3 col-md-6 col-lg-4" id="i4"></div>
</div>
<div class="row">
<div class="col-sm-3 col-md-6 col-lg-4" id="i5"></div>
<div class="col-sm-3 col-md-6 col-lg-4" id="i6"></div>
<div class="col-sm-3 col-md-6 col-lg-4" id="i7"></div>
<div class="col-sm-3 col-md-6 col-lg-4" id="i8"></div>
</div>
</body>
<script src="static/js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
});
function onLoading()
{
alert("Page Loaded");
Morris.Donut({
element: 'i1',
data: [
{label: "Download Sales", value: 12},
{label: "In-Store Sales", value: 30},
{label: "Mail-Order Sales", value: 20}
]
});
Morris.Donut({
element: 'i2',
data: [
{label: "Download Sales", value: 12},
{label: "In-Store Sales", value: 30},
{label: "Mail-Order Sales", value: 20}
]
});
Morris.Donut({
element: 'i3',
data: [
{label: "Download Sales", value: 12},
{label: "In-Store Sales", value: 30},
{label: "Mail-Order Sales", value: 20}
]
});
Morris.Donut({
element: 'i4',
data: [
{label: "Download Sales", value: 12},
{label: "In-Store Sales", value: 30},
{label: "Mail-Order Sales", value: 20}
]
});
Morris.Donut({
element: 'i5',
data: [
{label: "Download Sales", value: 12},
{label: "In-Store Sales", value: 30},
{label: "Mail-Order Sales", value: 20}
]
});
Morris.Donut({
element: 'i6',
data: [
{label: "Download Sales", value: 12},
{label: "In-Store Sales", value: 30},
{label: "Mail-Order Sales", value: 20}
]
});
Morris.Donut({
element: 'i7',
data: [
{label: "Download Sales", value: 12},
{label: "In-Store Sales", value: 30},
{label: "Mail-Order Sales", value: 20}
]
});
Morris.Donut({
element: 'i8',
data: [
{label: "Download Sales", value: 12},
{label: "In-Store Sales", value: 30},
{label: "Mail-Order Sales", value: 20}
]
});
}
</script>
它有效:)
答案 3 :(得分:1)
我也遇到了问题,解决问题的最佳方法是: 转到gradle控制台,看看哪里有警告,例如
警告:com.squareup.picasso.OkHttpDownloader:找不到引用的类com.squareup.okhttp.OkHttpClient
现在打开proguard规则文件并滚动到底部并添加行
-dontwarn com.squareup.okhttp.**
对于您在gradle控制台上找到的任何缺失的类,您基本上都添加了
行-dontwarn followed by class name
希望这对每个人都有效。祝你好运!