我用我的Android app.I HTTP核心和客戶端罐子上午SDK 23 我沒有得到任何編譯時和error.The應用程序運行,直到getRally方法運行被稱爲使用外部依賴關係。我的應用程序不使用添加的依賴在運行時
我mainactivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import com.rallydev.rest.RallyRestApi;
import com.rallydev.rest.request.QueryRequest;
import com.rallydev.rest.response.QueryResponse;
public class MainActivity extends AppCompatActivity
{
String host = "https://rally1.rallydev.com";
String applicationName = "Android-Rally";
RallyRestApi restApi;
Button buttonlogin;
EditText etemail,etpass;
QueryRequest qtestset;
QueryResponse response;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etemail=(EditText) findViewById(R.id.etemail);
etpass=(EditText) findViewById(R.id.etpassword);
buttonlogin=(Button) findViewById(R.id.btnlogin);
buttonlogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
if(etemail.equals("") && etpass.equals(""))
{
Toast.makeText(getApplicationContext(),"Enter your Rally Credentials",Toast.LENGTH_LONG).show();
}
else
{
try
{
getRally();
}
catch (URISyntaxException e)
{
e.printStackTrace();
}
qtestset = new QueryRequest("Defects");
qtestset.setLimit(1);
try
{
response = restApi.query(qtestset);
if(!response.wasSuccessful())
{
Toast.makeText(getApplicationContext(),"Login Un-Successful",Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(getApplicationContext(),"Login Successful",Toast.LENGTH_LONG).show();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
});
}
public RallyRestApi getRally() throws URISyntaxException {
String password = etemail.getText().toString();
String email=etpass.getText().toString();
restApi = new RallyRestApi(new URI(host), email,password);
restApi.setApplicationName(applicationName);
return restApi;
}
}
我的應用搖籃
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
packagingOptions
{
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/dependencies.txt'
}
defaultConfig {
applicationId "com.example.apetkar.rally_rest_android"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
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.2.0')
compile files('libs/gson-2.2.4.jar')
compile files('libs/commons-logging-1.1.1.jar')
compile files('libs/httpcore-4.2.4.jar')
compile files('libs/httpclient-4.2.5.jar')
compile files('libs/rally-rest-api-2.2.1.jar')
}
錯誤日誌
java.lang.NoSuchMethodError: No static method extractHost(Ljava/net/URI;)Lorg/apache/http/HttpHost; in class Lorg/apache/http/client/utils/URIUtils; or its super classes (declaration of 'org.apache.http.client.utils.URIUtils' appears in /system/framework/org.apache.http.legacy.boot.jar)
at org.apache.http.impl.client.DecompressingHttpClient.getHttpHost(DecompressingHttpClient.java:113)
at org.apache.http.impl.client.DecompressingHttpClient.execute(DecompressingHttpClient.java:108)
at com.rallydev.rest.client.HttpClient.executeRequest(HttpClient.java:157)
at com.rallydev.rest.client.HttpClient.doRequest(HttpClient.java:145)
at com.rallydev.rest.client.BasicAuthClient.doRequest(BasicAuthClient.java:56)
at com.rallydev.rest.client.HttpClient.doGet(HttpClient.java:221)
at com.rallydev.rest.RallyRestApi.query(RallyRestApi.java:172)
at com.example.apetkar.rally_rest_android.MainActivity$1.onClick(MainActivity.java:67)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
我沒有研究過這issue.The問題就是Android的默認org.apache.http.client.utils.URIUtils
是在運行時調用,不包含方法提取主機。方法extracthost在HttpClient.jar ..所以,我該如何強制應用程序調用Jar中的類而不是默認的Android類?
1)儘量不要使用JAR文件和'compile'代替的Gradle依賴關係。 2)你明白'編譯文件樹(導演:「libs''確實如果是這樣,你會意識到你並不需要明確地編譯每個單獨的JAR –
Yeah..I有權點擊瓶子並選擇加入? library..then(.jar)文件正在added.What的compilefiles你建議我在這裏做的??我會刪除的罐子,並添加編譯gradle這個依賴,並取回 – Akshay