gpt4 book ai didi

android - 如何避免在Android中依赖的无知?

转载 作者:行者123 更新时间:2023-12-03 04:28:08 24 4
gpt4 key购买 nike

我刚刚将一些项目导入我的Android Studio,并在最新版本的android SDK(即v7)上测试了该应用程序,但是当我尝试在旧设备上测试该应用程序时,该应用程序无法正常工作,因为该应用程序包含身份验证 Activity 在v7上成功运行,但在旧的android设备上无法正常运行。

org.apache.httpcomponents:httpmime:4.5.1'



我注意到上面的依赖关系被忽略了。我知道在API 23之后,此依赖关系已弃用。有什么方法可以避免通过gradle的无知吗?由于我的整个应用程序都基于http组件。

应用程序的Gradle文件为:

代码已更新
    apply plugin: 'com.android.application'

android {

compileSdkVersion 23
buildToolsVersion "25.0.0"
useLibrary 'org.apache.http.legacy'


defaultConfig {
applicationId "com.creative.nerdzprocollegemanager"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
debug {
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { res.srcDirs = ['src/main/res', 'src/main/res/values-fr'] } }
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'org.apache.httpcomponents:httpmime:4.5.1'
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'

}

应用程序功能是:
@Override
protected String doInBackground(Void...params) {
byte[] result;
String resultString = "";
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
try {
ArrayList < NameValuePair > nameValuePairs = new ArrayList < > ();
for (String key: postParams.keySet()) {
nameValuePairs.add(new BasicNameValuePair(key, postParams.get(key)));
}
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
HttpResponse response = httpClient.execute(httpPost);
StatusLine statusLine = response.getStatusLine();

if (statusLine.getStatusCode() == HttpURLConnection.HTTP_OK) {
errorMessage = "ok";
result = EntityUtils.toByteArray(response.getEntity());
resultString = new String(result, "UTF-8");
}
} catch (UnsupportedEncodingException e) {
errorMessage = "Encoding is not supported";
} catch (Exception e) {
errorMessage = "An error occurred";
}
return resultString;
}

@Override
protected void onPostExecute(String s) {
if (errorMessage.equals("ok")) {
sourceActivity.requestFinished(s, requestTag);
} else
sourceActivity.requestFailed(errorMessage, requestTag);
}
}

有什么方法可以避免通过gradle导致对依赖关系的无知吗?还是我应该使用一些替代httpclient的方法?请建议我一些解决方案,因为我对Android的使用经验不足。

最佳答案

在您的Gradle文件中将这一行添加到android的另一端

android{
...
useLibrary 'org.apache.http.legacy'
...
}

编辑:
也更换
compile group: 'cz.msebera.android' , name: 'httpclient', version:                                
'4.4.1.1'


compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'

要么
compile 'org.apache.httpcomponents:httpclient:4.5.1'

关于android - 如何避免在Android中依赖的无知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44426737/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com