Help us understand the problem. What is going on with this article?

Android 9 Pie Google Mapで'java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion'の対処法

More than 1 year has passed since last update.

前置き

小ネタになります:pushpin:
前回の記事でお伝えしましたが位置情報とGoogle Mapでアプリを作成していました。AVDのAndroid 9 PieでGoogle Mapを表示しようとすると例外がスローされましたので調査し解決しました。

例外メッセージ

E/AndroidRuntime: FATAL EXCEPTION: Thread-5
    Process: com.example.devnokiyo.locationsample, PID: 31378
    java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;
        at el.b(:com.google.android.gms.dynamite_mapsdynamite@12862026@12.8.62 (040700-199405334):3)
        at ek.a(:com.google.android.gms.dynamite_mapsdynamite@12862026@12.8.62 (040700-199405334):4)
        at em.a(:com.google.android.gms.dynamite_mapsdynamite@12862026@12.8.62 (040700-199405334):51)
        at com.google.maps.api.android.lib6.drd.ap.a(:com.google.android.gms.dynamite_mapsdynamite@12862026@12.8.62 (040700-199405334):11)
        at dw.a(:com.google.android.gms.dynamite_mapsdynamite@12862026@12.8.62 (040700-199405334):16)
        at dw.run(:com.google.android.gms.dynamite_mapsdynamite@12862026@12.8.62 (040700-199405334):61)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.ProtocolVersion" on path: DexPathList[[zip file "/system/priv-app/PrebuiltGmsCore/app_chimera/m/MapsDynamite.apk"],nativeLibraryDirectories=[/data/user_de/0/com.google.android.gms/app_chimera/m/00000006/MapsDynamite.apk!/lib/x86, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at ad.loadClass(:com.google.android.gms.dynamite_dynamiteloader@12862026@12.8.62 (040700-199405334):25)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at el.b(:com.google.android.gms.dynamite_mapsdynamite@12862026@12.8.62 (040700-199405334):3) 
        at ek.a(:com.google.android.gms.dynamite_mapsdynamite@12862026@12.8.62 (040700-199405334):4) 
        at em.a(:com.google.android.gms.dynamite_mapsdynamite@12862026@12.8.62 (040700-199405334):51) 
        at com.google.maps.api.android.lib6.drd.ap.a(:com.google.android.gms.dynamite_mapsdynamite@12862026@12.8.62 (040700-199405334):11) 
        at dw.a(:com.google.android.gms.dynamite_mapsdynamite@12862026@12.8.62 (040700-199405334):16) 
        at dw.run(:com.google.android.gms.dynamite_mapsdynamite@12862026@12.8.62 (040700-199405334):61) 

対処法

調査するとApache HTTP Legacy libraryに関する問題のようでAndroidManifest.xmlに以下を記述すれば良いことがわかりました。

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?hl=ja#apache-p
https://developers.google.com/maps/documentation/android-sdk/config#specify_requirement_for_apache_http_legacy_library
https://stackoverflow.com/questions/50461881/java-lang-noclassdeffounderrorfailed-resolution-of-lorg-apache-http-protocolve
https://qiita.com/takke/items/030af1054219e73531f6

終わりに

調査や解決自体は難しくないと思いますが、Android Studio 3.2の雛形で作成されたGoogle Mapで利用されているとは思いませんでした:tired_face:

devnokiyo
ゲーム関連のWebサイトや時々モバイルアプリを作るエンジニアです。ご縁がありTechpitさんでプログラミング教材を執筆しました。 犬とデジモノガジェットが好きです。犬に関するWebサイトかモバイルアプリを個人開発しようとしてます。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした