duk*_*ing 275 android google-maps gradle apache-httpcomponents android-9.0-pie
当我使用Android Studio 3.1构建Android P的应用程序时,我遇到了这样的错误,可以制作apk,但是当我在Android P模拟器上使用它时,它会崩溃并抛出以下信息,更多细节请参见图片.
java.lang.NoClassDefFoundError:解析失败:Lorg/apache/http/ProtocolVersion
App模块下的build.gradle的一部分在下面,有人见过这个吗?并给出一些建议?非常感谢.
android {
compileSdkVersion 'android-P'
buildToolsVersion '28-rc1'
useLibrary 'org.apache.http.legacy'
//for Lambda
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
defaultConfig {
applicationId "xxx.xxx.xxx"
minSdkVersion 17
targetSdkVersion 27
versionCode xxxx
versionName "Vx.x.x"
multiDexEnabled true
//other setting required
ndk {
abiFilters 'armeabi', 'armeabi-v7a', 'armeabi-v8a', 'x86', 'x86_64', 'mips', 'mips64'
}
Run Code Online (Sandbox Code Playgroud)
Ada*_*amK 730
更新:这不再是一种变通方法,如果您的应用面向API级别28(Android 9.0)或更高级别并且使用适用于Android的Google Maps SDK(或者您的应用使用Apache HTTP Legacy库),则需要此方法.它现在包含在官方文档中.公共问题已关闭的预期行为.
这是Google Play服务方面的一个错误,在修复之前,您应该可以通过将其添加到标记AndroidManifest.xml
内部来解决此问题<application>
:
AndroidManifest.xml
pra*_*ala 46
此链接android-9.0-changes-28 - > Apache HTTP客户端弃用解释了将以下内容添加到AndroidManifest.xml的原因:
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
Run Code Online (Sandbox Code Playgroud)
在Android 6.0中,我们删除了对Apache HTTP客户端的支持.从Android 9开始,该库将从bootclasspath中删除,默认情况下不可用于应用程序.
小智 28
在您的 AndroidManifest.xml 中添加这两行。
android:usesCleartextTraffic="true"
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
Run Code Online (Sandbox Code Playgroud)
请参阅下面的代码
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity android:name=".activity.SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
</application>
Run Code Online (Sandbox Code Playgroud)
Dar*_*ush 25
请执行以下任何操作:
1-将play-services-maps库更新到最新版本:
com.google.android.gms:play-services-maps:16.1.0
Run Code Online (Sandbox Code Playgroud)
2-或在<application>
元素中包含以下声明AndroidManifest.xml
.
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
Run Code Online (Sandbox Code Playgroud)
Git*_*esh 14
要在Android 9.0 Pie中完美运行org.apache.http.legacy,请创建一个xml文件 res/xml/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)
并在您的AndroidManifest.xml中添加2个标签
android:networkSecurityConfig =“ @ xml / network_security_config” android:name =“ org.apache.http.legacy”
<?xml version="1.0" encoding="utf-8"?>
<manifest......>
<application android:networkSecurityConfig="@xml/network_security_config">
<activity..../>
......
......
<uses-library
android:name="org.apache.http.legacy"
android:required="false"/>
</application>
Run Code Online (Sandbox Code Playgroud)
还添加useLibrary 'org.apache.http.legacy'
您的应用程序构建gradle
android {
compileSdkVersion 28
defaultConfig {
applicationId "your application id"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
useLibrary 'org.apache.http.legacy'
}
Run Code Online (Sandbox Code Playgroud)
小智 13
如果您将Android 9.0与旧版jar一起使用,则必须使用。在您的mainfest文件中。
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
小智 13
如果您使用com.google.android.gms:play-services-maps:16.0.0
或更低版本并且您的应用面向 API 级别 28 (Android 9.0) 或更高版本,则必须在 AndroidManifest.xml 的元素中包含以下声明
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
Run Code Online (Sandbox Code Playgroud)
小智 8
如果您使用 com.google.android.gms:play-services-maps:16.0.0 或更低版本,并且您的应用面向 API 级别 28 (Android 9.0) 或更高版本,则必须在 AndroidManifest 的元素中包含以下声明。 xml。
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
Run Code Online (Sandbox Code Playgroud)
如果您使用的是 com.google.android.gms:play-services-maps:16.1.0,这将为您处理,如果您的应用面向较低的 API 级别,则不需要。
这可能是迟到的答案。但是,我希望它可以节省一些时间:
如果您使用 com.google.android.gms:play-services-maps:16.0.0 或更低版本,并且您的应用面向 API 级别 28 (Android 9.0)或更高版本,则必须在AndroidManifest的元素中包含以下声明。 xml
<application
...
...
android:usesCleartextTraffic="true"
android:requestLegacyExternalStorage="true">
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
</application>
Run Code Online (Sandbox Code Playgroud)
注:android:requestLegacyExternalStorage="true"
所需的Android 10+访问存储R / W
Android 6.0在 android manifest 中的 application 元素下引入了useCleartextTraffic属性。Android P 中的默认值为“false”。将此设置为true表示应用程序打算使用清晰的网络流量。
如果您的应用在Android 10 设备上运行时选择退出范围存储,建议您继续在应用的清单文件中将requestLegacyExternalStorage设置为 true。这样,您的应用就可以在运行Android 10 的设备上继续按预期运行
在本机反应中,我遇到了错误,未显示地图并关闭应用程序,运行 adb logcat 并在控制台中显示错误:
java.lang.NoClassDefFoundError:failed resolution of :Lorg/apache/http/ProtocolVersion
Run Code Online (Sandbox Code Playgroud)
通过在 androidManifest.xml 中添加来修复它
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
79656 次 |
最近记录: |