Я пытаюсь добавить карту во фрагмент, и у меня нет никаких признаков ошибки в моей IDE, но приложение просто упало на устройстве. Я не знаю, что случилось. Я уже включил SDK своей карты для Android в консоли, и все, что я сделал, это просто изменил MapsActivity, созданный в Android Studio, на MapsFragment.
MainActivity.kt
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val fragmentTransaction = supportFragmentManager.beginTransaction()
fragmentTransaction.add(R.id.fragment_container, MapsFragment.newInstance()).commit()
}
}
MapsFragment.kt
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.android.gms.maps.*
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.MarkerOptions
class MapsFragment : Fragment(), OnMapReadyCallback {
private lateinit var mMap: GoogleMap
companion object {
fun newInstance() = MapsFragment()
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_maps, container, false)
val mapFragment = childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
mapFragment.getMapAsync(this)
}
override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap
// Add a marker in Sydney and move the camera
val sydney = LatLng(3.0414067, 101.5901829)
mMap.addMarker(MarkerOptions().position(sydney).title("Marker in Sydney"))
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney))
}
}
fragment_maps.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsFragment">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
И все, что я получил, это эта ошибка.
E/AndroidRuntime: FATAL EXCEPTION: Thread-7
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;
at ep.b(:com.google.android.gms.dynamite_mapsdynamite@13280056@13.2.80 (040800-211705629):3)
at eo.a(:com.google.android.gms.dynamite_mapsdynamite@13280056@13.2.80 (040800-211705629):4)
at eq.a(:com.google.android.gms.dynamite_mapsdynamite@13280056@13.2.80 (040800-211705629):55)
at com.google.maps.api.android.lib6.drd.ap.a(:com.google.android.gms.dynamite_mapsdynamite@13280056@13.2.80 (040800-211705629):11)
at dx.a(:com.google.android.gms.dynamite_mapsdynamite@13280056@13.2.80 (040800-211705629):17)
at dx.run(:com.google.android.gms.dynamite_mapsdynamite@13280056@13.2.80 (040800-211705629):65)
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/n/x86_64, /system/lib64]]
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@13280056@13.2.80 (040800-211705629):25)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at ep.b(:com.google.android.gms.dynamite_mapsdynamite@13280056@13.2.80 (040800-211705629):3)
at eo.a(:com.google.android.gms.dynamite_mapsdynamite@13280056@13.2.80 (040800-211705629):4)
at eq.a(:com.google.android.gms.dynamite_mapsdynamite@13280056@13.2.80 (040800-211705629):55)
at com.google.maps.api.android.lib6.drd.ap.a(:com.google.android.gms.dynamite_mapsdynamite@13280056@13.2.80 (040800-211705629):11)
at dx.a(:com.google.android.gms.dynamite_mapsdynamite@13280056@13.2.80 (040800-211705629):17)
at dx.run(:com.google.android.gms.dynamite_mapsdynamite@13280056@13.2.80 (040800-211705629):65)