我開始學習android並嘗試調用WebService。沒有WebService調用的基本代碼運行良好。任務執行失敗':app:transformClassesWithJarMergingForDebug'
然後我添加了兩個文件到庫 android-support-v4.jar和android-async-http-1.4.4.jar。
我收到以下錯誤
錯誤:執行失敗的任務 ':應用程序:transformClassesWithJarMergingForDebug'。
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/util/MapCollections$ArrayIterator.class
下面是代碼的一部分,這是需要
public void invokeWS(RequestParams params) {
String url = "http://localhost:8080/OnlineStore/kmsg/grocery/Login";
AsyncHttpClient client = new AsyncHttpClient();
client.post(url, params, new AsyncHttpResponseHandler(){
@Override
public void onSuccess(String response){
try{
JSONObject jobj = new JSONObject(response);
Toast.makeText(getApplicationContext(), "You are logged in", Toast.LENGTH_LONG).show();
}
catch(JSONException jexec){
Toast.makeText(getApplicationContext(), "Error Occured [Server's JSON response might be invalid]!", Toast.LENGTH_LONG).show();
jexec.printStackTrace();
}
} // End of onSuccess
@Override
public void onFailure(int Status, Throwable error, String content){
Toast.makeText(getApplicationContext(), "You failed to login", Toast.LENGTH_LONG).show();
} // End of onFailure
}
); // End of post function
下面是我的build.gradle 應用插件:'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "kmsg.com.listwithadapters"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
compile files('libs/android-async-http-1.4.4.jar')
}
從很明顯的錯誤,有是一些重複的條目,但爲什麼構建系統不能自行解決它?任何快速的見解都會幫助我理解這個錯誤的原因。
感謝網友
minifyEnabled false => true。並且您是否需要multiDexEnabled爲true? –
minifyEnabled true尚未解決問題。另一點是,當我只建造時,它是成功的。只有當我運行它時纔會發生錯誤。但錯誤說,BUILD ERROR。有點奇怪! – Harry
怎樣去除編譯文件('libs/android-async-http-1.4.4.jar')? –