每当我尝试显示Google Maps窗口小部件我的应用程序崩溃时,日志中给出的原因是:
W/com.foody.food( 6310): Unsupported class loader
W/com.foody.food( 6310): Skipping duplicate class check due to unsupported classloader
I/DynamiteModule( 6310): Considering local module com.google.android.gms.maps_dynamite:0 and remote module com.google.android.gms.maps_dynamite:221
I/DynamiteModule( 6310): Selected remote version of com.google.android.gms.maps_dynamite, version >= 221
V/DynamiteModule( 6310): Dynamite loader version >= 2, using loadModule2NoCrashUtils
W/com.foody.food( 6310): Unsupported class loader
I/Google Maps Android API( 6310): Google Play services client version: 12451000
I/Google Maps Android API( 6310): Google Play services package version: 15090039
I/DpmTcmClient( 6310): RegisterTcmMonitor from: com.android.okhttp.TcmIdleTimerMonitor
E/GoogleMapController( 6310): Cannot enable MyLocation layer as location permissions are not granted
E/AndroidRuntime( 6310): FATAL EXCEPTION: Thread-4
E/AndroidRuntime( 6310): Process: com.foody.foody, PID: 6310
E/AndroidRuntime( 6310): java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;
E/AndroidRuntime( 6310): at fb.b(:com.google.android.gms.dynamite_mapsdynamite@15090083@15.0.90 (100408-231259764):3)
E/AndroidRuntime( 6310): at fa.a(:com.google.android.gms.dynamite_mapsdynamite@15090083@15.0.90 (100408-231259764):3)
E/AndroidRuntime( 6310): at fc.a(:com.google.android.gms.dynamite_mapsdynamite@15090083@15.0.90 (100408-231259764):15)
E/AndroidRuntime( 6310): at com.google.maps.api.android.lib6.drd.al.a(:com.google.android.gms.dynamite_mapsdynamite@15090083@15.0.90 (100408-231259764):6)
E/AndroidRuntime( 6310): at ee.a(:com.google.android.gms.dynamite_mapsdynamite@15090083@15.0.90 (100408-231259764):23)
E/AndroidRuntime( 6310): at ee.run(:com.google.android.gms.dynamite_mapsdynamite@15090083@15.0.90 (100408-231259764):8)
E/AndroidRuntime( 6310): Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.ProtocolVersion" on path: DexPathList[[zip file "/data/user_de/0/com.google.android.gms/app_chimera/m/00000035/MapsDynamite.apk"],nativeLibraryDirectories=[/data/user_de/0/com.google.android.gms/app_chimera/m/00000035/MapsDynamite.apk!/lib/arm64-v8a, /system/lib64]]
E/AndroidRuntime( 6310): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
E/AndroidRuntime( 6310): at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/AndroidRuntime( 6310): at ad.loadClass(:com.google.android.gms.dynamite_dynamiteloader@15090083@15.0.90 (100408-231259764):4)
E/AndroidRuntime( 6310): at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime( 6310): ... 6 more
I/Process ( 6310): Sending signal. PID: 6310 SIG: 9
Lost connection to device.
我的AndroidManifest看起来像这样:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.foody.foody">
<!-- The INTERNET permission is required for development. Specifically,
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="foody"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyBM8ywYw1UDb3aXaTF3w21EJ86ePWmAkPE"/>
</application>
</manifest>
我尝试以这种方式显示地图:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'reservation.dart';
import 'dart:async';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:flutter/services.dart';
import 'feed.dart';
class info extends StatelessWidget {
info([this.id]);
Completer<GoogleMapController> _controller = Completer();
static final CameraPosition _kGooglePlex = CameraPosition(
target: LatLng(37.42796133580664, -122.085749655962),
zoom: 14.4746,
);
int id;
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Reservation(id)),
);
},
icon: Icon(Icons.calendar_today),
label: Text('Book a Table'),
backgroundColor: Colors.blueGrey,
),
body: _buildBody(context),
);
}
Widget _buildBody(BuildContext context) {
return StreamBuilder<QuerySnapshot>(
stream: Firestore.instance
.collection('restaurants')
.where('id', isEqualTo: id)
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return LinearProgressIndicator();
return _buildList(context, snapshot.data.documents);
},
);
}
Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot) {
return ListView(
physics: BouncingScrollPhysics(),
shrinkWrap: true,
children: <Widget>[
new Container(
decoration: new BoxDecoration(boxShadow: [
new BoxShadow(
color: Colors.blueGrey,
blurRadius: 20.0,
)
]),
child: new Image.network(snapshot[0].data['picURL']),
),
Padding(
padding: const EdgeInsets.all(7.0),
child: Text(snapshot[0].data['name'],
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 36)),
),
Padding(
padding: const EdgeInsets.all(7.0),
child: Text(snapshot[0].data['desc'],
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 36)),
),
Container(
height: 500.0,
width: 500.0,
child: GoogleMap(
rotateGesturesEnabled: true,
scrollGesturesEnabled: true,
tiltGesturesEnabled: true,
mapType: MapType.normal,
initialCameraPosition: _kGooglePlex,
onMapCreated: (GoogleMapController controller) {
controller.addMarker(
MarkerOptions(
position: LatLng(37.42796133580664, -122.085749655962),
),
);
_controller.complete(controller);
},
),
),
],
);
}
}
我尝试添加simple_permissions插件,但是该插件似乎有自己的错误,因此我停了下来。该代码在模拟器上运行良好,但是仅在我的手机上崩溃。 谢谢
答案 0 :(得分:2)
我遇到类似的错误,将下面的代码放在 AndroidManifest.xml 中即可解决该问题。
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
答案 1 :(得分:0)
解决方案是将您的项目升级到AndroidX。
但是请不要手动执行,请按照以下说明使用Android Studio:https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility