我已经在安卓系统上实现了谷歌地图,在安卓Pie之前运行良好。但在10日,我将遭遇以下撞车事故。
com.google.android.apps.gmm.map.util.jni.zza: Exception while extracting native library.
at com.google.android.apps.gmm.map.util.jni.NativeHelper.safeLoadLibrary(NativeHelper.java:53)
at com.google.android.apps.gmm.map.util.jni.NativeHelper.ensureLibraryLoaded(NativeHelper.java:17)
at com.google.android.apps.gmm.map.internal.store.diskcache.NativeSqliteDiskCacheImpl.<clinit>(NativeSqliteDiskCacheImpl.java:141)
at com.google.android.apps.gmm.map.internal.store.diskcache.NativeSqliteDiskCacheImpl.createOrOpenDatabase(NativeSqliteDiskCacheImpl.java:4)
at com.google.android.apps.gmm.map.internal.store.diskcache.zzf.zza(SqliteDiskCache.java:6)
at com.google.android.apps.gmm.map.internal.store.diskcache.zzg.zzc(SqliteDiskCacheProvider.java:104)
at com.google.android.apps.gmm.map.internal.store.diskcache.zzg.zza(SqliteDiskCacheProvider.java:31)
at com.google.android.apps.gmm.map.internal.store.zzbe.zza(TileStoreFactory.java:97)
at com.google.android.apps.gmm.map.internal.store.zzbe.zza(TileStoreFactory.java:67)
at com.google.android.libraries.maps.bl.zzex.zza(TileOverlayFactory.java:56)
at com.google.android.libraries.maps.bl.zzdq.zza(PhoenixGoogleMapActivityEnvironment.java:127)
at com.google.android.libraries.maps.bl.zzdq.zzd(PhoenixGoogleMapActivityEnvironment.java:210)
at com.google.android.libraries.maps.av.zzg.zza(MapContainer.java:26)
at com.google.android.libraries.maps.gu.zzat.zza(RendererFactoryImpl.java:177)
at com.google.android.libraries.maps.it.zzav.zza(GoogleMapImpl.java:59)
at com.google.android.libraries.maps.it.zzci.zza(MapFragmentDelegateImpl.java:3)
at com.google.android.libraries.maps.it.zzcg.zza(MapFragmentDelegateImpl.java:15)
at com.google.android.libraries.maps.SupportMapFragment$zza.onCreateView(SupportMapFragment.java:15)
at com.google.android.gms.dynamic.zae.zaa(com.google.android.gms:play-services-base@@17.1.0:4)
at com.google.android.gms.dynamic.DeferredLifecycleHelper.zaa(com.google.android.gms:play-services-base@@17.1.0:9)
at com.google.android.gms.dynamic.DeferredLifecycleHelper.onCreateView(com.google.android.gms:play-services-base@@17.1.0:25)
at com.google.android.libraries.maps.SupportMapFragment.onCreateView(SupportMapFragment.java:34)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2600)
at androidx.fragment.app.FragmentManagerImpl.ensureInflatedFragmentView(FragmentManagerImpl.java:1138)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:851)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1133)
at androidx.fragment.app.FragmentManagerImpl.addFragment(FragmentManagerImpl.java:1393)
at androidx.fragment.app.FragmentManagerImpl.onCreateView(FragmentManagerImpl.java:3205)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:239)
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1061)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:997)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:126)
at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:95)
如果需要任何其他细节,我将乐意为您服务。我们非常感谢对此事的任何帮助或暗示。
编辑-编码部分
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val mapFragment = childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
mapFragment.getMapAsync {
map = it
it.setLocationSource(LocationSource)
}
}
布局
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:name="com.google.android.libraries.maps.SupportMapFragment"
class="com.google.android.libraries.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</fragment>
<ImageView
android:id="@+id/my_loc_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:padding="10dp"
android:layout_gravity="bottom|end"
android:src="@drawable/ic_my_location"/>
<ImageView
android:id="@+id/menu_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
android:padding="10dp"
android:layout_gravity="top|start"
android:src="@drawable/ic_hamburger"/>
</FrameLayout>
</layout>
解决方法经过多次尝试和错误,发现错误是构建工具版本将com.android.tools.build:gradle:3.5.1
更改为com.android.tools.build:gradle:3.3.1
修复它。
用以下代码替换XML,
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--Change start-->
<FrameLayout
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</FrameLayout>
<!-- Change end-->
<ImageView
android:id="@+id/my_loc_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:padding="10dp"
android:layout_gravity="bottom|end"
android:src="@drawable/ic_my_location"/>
<ImageView
android:id="@+id/menu_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
android:padding="10dp"
android:layout_gravity="top|start"
android:src="@drawable/ic_hamburger"/>
</FrameLayout>
</layout>
你的碎片编码部分,
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
val smf = SupportMapFragment.newInstance()
childFragmentManager.beginTransaction().replace(R.id.map, smf).commit()
smf.getMapAsync({
Toast.makeText(activity,"Map Ready",Toast.LENGTH_SHORT).show()
})
}
享受你的一天。