Android M 용 build.grade에 Apache HTTP API (레거시)를 컴파일 시간 종속성으로 추가하는 방법은 무엇입니까?
여기 에서 언급했듯이 Android M은 Apache HTTP API를 지원하지 않습니다. 문서 상태 :
대신 HttpURLConnection 클래스를 사용하십시오.
또는
Apache HTTP API를 계속 사용하려면 먼저 build.gradle 파일에서 다음 컴파일 시간 종속성을 선언해야합니다.
android {useLibrary 'org.apache.http.legacy'}
나는 그러나, 나는 아직도, HttpURLConnection의에 HttpClient를 내 프로젝트의 사용의 변환 다량이 필요 HttpClient를 몇 지역에서 사용할 수 있습니다. 따라서 'org.apache.http.legacy'를 컴파일 타임 종속성으로 선언하려고하지만 build.gradle에서 오류가 발생합니다.
Gradle DSL 메서드를 찾을 수 없음 : 'useLibrary ()'
내 질문은 : 어떻게 'org.apache.http.legacy'를 프로젝트에서 컴파일 타임 종속성으로 선언합니까?
어떤 도움이라도 대단히 감사합니다. 감사
API 23의 경우 :
최상위 수준 build.gradle-/build.gradle
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}
...
모듈 별 build.gradle-/app/build.gradle
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
useLibrary 'org.apache.http.legacy'
...
}
공식 문서 (미리보기 용) : http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client
최신 Android Gradle 플러그인 변경 로그 : http://tools.android.com/tech-docs/new-build-system
또 다른 대안은 jbundle 종속성을 추가하는 것입니다. Android Studio는 "cannot resolve symbol ..."이라는 메시지를 표시하지 않으므로 Android Studio에 더 친숙합니다.
dependencies {
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
}
build.gradle 파일에서 > 노트에 따라 useLibrary 'org.apache.http.legacy' 를 추가하십시오 .Android 6.0 Changes
Apache HTTP Client Removal
android {
...
useLibrary 'org.apache.http.legacy'
...
}
누락 된 링크 오류를 방지하려면 종속성에 추가
dependencies {
provided 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
}
'제공됨'을 사용하면 종속성이 apk에 포함되지 않습니다.
: 그냥 파일 복사 org.apache.http.legacy.jar
에서 Android/Sdk/platforms/android-23/optional
폴더를 프로젝트 폴더로를 app/libs
.
23.1.1의 매력처럼 작동했습니다.
Android 9 (Pie)에 대한 참고 사항입니다.
또한 useLibrary 'org.apache.http.legacy'
AndroidManifest.xml에 추가해야합니다.
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
출처 : https://developer.android.com/about/versions/pie/android-9.0-changes-28
답변이 약간 오래 되었기 때문에 내 솔루션을 넣을 것입니다 (저에게 도움이 된 것), 다른 사람에게 도움이 될 수 있습니다 ... 해결책이 없는 Apache 의 공식 문서 에서 솔루션을 가져 왔습니다 .
1 / gradle에서 :
dependencies {
...
// This is the maintained version from apache.
compile group: 'cz.msebera.android', name: 'httpclient', version: '4.4.1.1'
}
2/ in the rest of the app replace the org.apache.http
by cz.msebera.android.httpclient
and all your imports (dependencies) will be fixed. you can just do ctrl+shift+R and replace it in the whole project.
I solved this problem like so:
1.) Set classpath in top-level build file as GUG mentioned:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0-beta2'
}
allprojects {
repositories {
jcenter()
}
}
}
2.) In build file of specific module:
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 'android-MNC'
buildToolsVersion '23.0.0 rc3'
}
FWIW the removal of Apache library was foreshadowed a while ago. Our good friend Jesse Wilson gave us a clue back in 2011: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
Google stopped working on ApacheHTTPClient a while ago, so any library that is still relying upon that should be put onto the list of deprecated libraries unless the maintainers update their code.
<rant>
I can't tell you how many technical arguments I've had with people who insisted on sticking with Apache HTTP client. There are some major apps that are going to break because management at my not-to-be-named previous employers didn't listen to their top engineers or knew what they were talking about when they ignored the warning ... but, water under the bridge.
I win.
</rant>
it should help:
android {
...
useLibrary 'org.apache.http.legacy'
...
}
To avoid missing link errors add to dependencies
dependencies {
provided 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
}
or
dependencies {
compileOnly 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
}
because
Warning: Configuration 'provided' is obsolete and has been replaced with 'compileOnly'.
To resolve the issues make sure you are using build tools version "23.0.0 rc2" with the following tools build gradle dependency:
classpath 'com.android.tools.build:gradle:1.3.0-beta2'
'Programming' 카테고리의 다른 글
그렇지 않으면 StateProvider에서 (0) | 2020.08.27 |
---|---|
C 문자 배열 초기화 (0) | 2020.08.27 |
AndroidRuntime 오류 : Parcel : 값을 마샬링 할 수 없습니다. (0) | 2020.08.27 |
rsync-rsync 로그에서 f +++++++++는 무엇을 의미합니까? (0) | 2020.08.27 |
Linux에서 데몬 만들기 (0) | 2020.08.27 |