在我的应用程序中,我只启用 Proguard 。启用后,使用 org.apache.http 进行 api 调用无效。
我的 targetSDKversion是23 ,所以我添加了使用org.apache.htpp的库
没有proguard,发布APK工作正常。但启用后,apk无法正常工作。
问题是api没有正常调用
在我的 proguard_rule.pro
中-dontwarn org.apache.http.**
-dontwarn android.net.**
-keep class org.apache.http.** { *; }
添加这三行后,会生成发布apk 。在那之前我得到了像
这样的警告Warning:library class org.apache.http.conn.scheme.LayeredSocketFactory extends or implements program class org.apache.http.conn.scheme.SocketFactory
Gradle文件
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.google.android.gms:play-services-ads:7.8.0'
compile 'com.android.support:appcompat-v7:23.1.1'
compile('com.android.support:support-v4:21.0.3') {
exclude module: 'support-v4'
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
useLibrary 'org.apache.http.legacy'
defaultConfig {
minSdkVersion 11
targetSdkVersion 23
}
buildTypes {
release {
// signingConfig signingConfigs.release
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['submodules/linphone/mediastreamer2/java/src','submodules/linphone/java/j2se','submodules/linphone/java/common','submodules/linphone/java/impl','submodules/externals/axmlrpc/src/main/java','submodules/linphone/coreapi/help/java','src']
resources.srcDirs = ['submodules/linphone/mediastreamer2/java/src','submodules/linphone/java/j2se','submodules/linphone/java/common','submodules/linphone/java/impl','submodules/externals/axmlrpc/src/main/java','submodules/linphone/coreapi/help/java','src']
aidl.srcDirs = ['submodules/linphone/mediastreamer2/java/src','submodules/linphone/java/j2se','submodules/linphone/java/common','submodules/linphone/java/impl','submodules/externals/axmlrpc/src/main/java','submodules/linphone/coreapi/help/java','src']
renderscript.srcDirs = ['submodules/linphone/mediastreamer2/java/src','submodules/linphone/java/j2se','submodules/linphone/java/common','submodules/linphone/java/impl','submodules/externals/axmlrpc/src/main/java','submodules/linphone/coreapi/help/java','src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDir 'libs'
java.exclude '**/mediastream/MediastreamerActivity.java'
}
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
dexOptions {
javaMaxHeapSize "4g"
preDexLibraries = false
}
}
任何人都可以帮我在启用Proguard的版本中使用 org.apache.http
答案 0 :(得分:0)
试试希望它有所帮助,
-dontwarn org.apache.**
因为警告可以在proguard中忽略,因此而不是-dontwarn org.apache.http.**
例如,
-keep class org.apache.http.**
-keep interface org.apache.http.**
-dontwarn org.apache.**
-libraryjars /libs/httpmime-4.3.5.jar
-libraryjars /libs/httpclient-4.3.5.jar
-libraryjars /libs/httpclient-cache-4.3.5.jar
-libraryjars /libs/httpcore-4.3.5.jar
添加
compile files('libs/httpmime-4.3.5.jar')
compile files('libs/httpclient-4.3.5.jar')
compile files('libs/httpclient-cache-4.3.5.jar')
compile files('libs/httpcore-4.3.2.jar')