我在开发期间成功构建了应用程序的调试版,尽管伴随着以下警告:
"W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable.
当我执行fullRelease构建时,我遇到以下错误:
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForFullRelease'.
> java.io.IOException: Can't write [/PATH_TO_APP/app/build/intermediates/transforms/proguard/full/release/jar s/3/1f/main.jar] (Can't read [/PATH_TO_APP/app/build/intermediates/exploded- aar/com.android.support/support- fragment/24.2.1/jars/classes.jar(;;;;;;**.class)] (Duplicate zip entry [android/support/v4/app/r.class == classes.jar:android/support/v4/app/Fragment$1.class]))
我正在整合支持库,以便在Android 6.0+中使用AppCompat权限。以下是我的build.gradle文件。
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion '24.0.3'
useLibrary 'org.apache.http.legacy'
ext {
supportLibVersion = '24.2.1'
}
lintOptions {
abortOnError false
}
defaultConfig {
applicationId "com.whatever.appname"
testApplicationId 'com.whatever.appname'
versionCode 8
minSdkVersion 9
targetSdkVersion 24
}
buildTypes {
debug {
debuggable true
minifyEnabled false
signingConfig signingConfigs.debug
}
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFile 'PATH_TO_PROGUARD/proguard-project.txt'
}
}
signingConfigs {
release {
keyPassword 'PASSWORD'
storePassword 'PASSWORD'
keyAlias 'ALIAS'
storeFile file('PATH_TO_KEYSTORE/keystore_file')
}
debug {
keyAlias 'KEY_ALIAS'
keyPassword 'PASSWORD'
storePassword 'PASSWORD'
storeFile file('PATH_TO_DEBUG_KEYSTORE/debug.keystore')
}
}
productFlavors {
full {
versionName '10.6.0'
applicationId 'com.whatever.appname'
testApplicationId 'APP_TEST_ID'
versionCode 8
proguardFile '/PATH_TO_PROGUARD/proguard-project.txt'
signingConfig signingConfigs.release
targetSdkVersion 24
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
dependencies {
compile 'ch.acra:acra:4.7.0'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:support-compat:24.2.1'
compile 'com.android.support:support-core-utils:24.2.1'
compile 'com.android.support:support-core-ui:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:support-annotations:24.2.1'
compile fileTree(include: ['*.jar'], dir: 'libs')
}
在我的proguard-project.txt文件中,由于使用了一些已弃用的类,我的应用程序的一些相关和特定条目是:
-keep class org.apache.http.** { *; }
-dontwarn org.apache.commons.**
-dontwarn org.apache.http.**
-dontwarn android.net.http.AndroidHttpClient
-dontwarn com.google.android.gms.**
-dontwarn com.android.volley.toolbox.**
-ignorewarnings
对于那些好奇的人,当我从构建中完全删除proguard进程并执行应用程序清理,然后是fullRelease构建时,我遇到的错误是不同的:
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/graphics/drawable/AnimatedVectorDrawableCompat$1;
和
Error:Execution failed for task ':app:transformClassesWithDexForFullRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException
任何人都可以了解我遇到的错误,并可能建议一个解决方法吗?当然,我最好将proguard流程纳入构建过程。
更新:此外,当从命令行运行任何gradle任务时,我遇到了错误:
problem occurred evaluating project ':app'.
> java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0
让我相信AppCompat或Support库中的某个地方正在使用Java 8语言功能,而我正在编译Java 7。
答案 0 :(得分:0)
不确定配偶,但如果我是你,我试着看看这个
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:support-compat:24.2.1'
也许appcompact和支持紧凑并没有完全顺利。
尝试删除appcompact并使用支持(或反之亦然)
希望有所帮助
答案 1 :(得分:0)
我的问题的解决方案是一个配置解决方案,它支持文档Use Java 8 Language Features中描述的Java 8语言功能。
我采取的解决问题的确切步骤是: 将以下内容添加到build.gradle defaultConfig部分。
import sys
import tweepy
import json
consumer_key = 'XXXX'
consumer_secret = 'XXXX'
access_key = 'XXXX'
access_secret = 'XXXX'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
file = open('today.txt', 'a')
class CustomStreamListener(tweepy.StreamListener):
def on_status(self, status):
print (status.text)
def on_data(self, data):
json_data = json.loads(data)
file.write(str(json_data))
def on_error(self, status_code):
print >> sys.stderr, 'Encountered error with status code:', status_code
return True # Don't kill the stream
def on_timeout(self):
print >> sys.stderr, 'Timeout...'
return True # Don't kill the stream
sapi = tweepy.streaming.Stream(auth, CustomStreamListener())
sapi.filter(track=['twitter'])
将以下内容添加到build.gradle buildTypes,debug&分别发布:
jackOptions {
enabled true
}
将build.gradle sourceCompatability和targetCompatability Java版本从VERSION_1_7更改为以下
debug{
shrinkResources false
}
release {
shrinkResources false
}
执行这些更改后,我执行了clean和Build,并且能够成功构建应用程序。