android - 地理定位器出错:如果我在 pubspec.yaml 文件中添加 ^3.0.0,则无法构建 android 应用程序
问题描述
如果我geolocator: ^3.0.0
在pubspec.yaml
Flutter 中添加文件,我的 Android 应用程序将无法构建并引发如下错误:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> com.android.build.api.transform.TransformException: Error while generating the main dex list.
我尝试将目标和 buildtool 版本从 27 更改为 28 仍然遇到同样的问题
build.gradle 文件。
android {
compileSdkVersion 28
dexOptions {
javaMaxHeapSize "4g"
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
multiDexEnabled true
applicationId "com.depl.toours.business"
minSdkVersion 16
targetSdkVersion 27
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
main.dart 文件。
class MyDemoPage extends State<AccommodationPage> {
@override
void initState() {
super.initState();
propertyList = new List<String>();
propertyList.add('Hotel');
propertyList.add('Gust House');
_getCurrentPosition();
}
_getCurrentPosition() async{
GeolocationStatus status = await Geolocator().checkGeolocationPermissionStatus(locationPermission: GeolocationPermission.location);
print('GPS: $status');
Position position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
double lat = position.latitude;
double lng = position.longitude;
print('LatLng: ${lat} & ${lng}');
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: new Text('Accommodation'),
),
body: _getBody(),
);
}
}
我期待包中的当前位置坐标geolocator: ^3.0.0
,也包含multidexEnabled true
在defaultConfig
(build.gradle
文件)中。
解决方案
我想你要么需要使用
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 28
multiDexEnabled true
}
...
}
在您的设置中,这是缺失的
minSdkVersion 21
targetSdkVersion 28
或者如果您需要支持 min SDK < 21
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 28
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.3'
}
在您的设置中,这是缺失的
dependencies {
compile 'com.android.support:multidex:1.0.3'
}
有关更多详细信息,请参阅https://developer.android.com/studio/build/multidex
推荐阅读
- hsm - 如何将 Encrypted ZMK.LMK 导入 HSM 以进行三重 DES 操作?
- firebase - 即使在插入值后文本字段仍显示错误消息
- android - 团队中的每个开发者都可以使用自己的上传密钥来更新 Play 商店中的应用吗
- c - 给自己定义一个宏符号
- javascript - 如何检查给定的 URL 在 Java 和 JavaScript 中是否存在
- python - 如何解决不可哈希类型的问题:'numpy.ndarray'
- android - Flutter Webview 在点击功能的抽屉导航中不起作用
- javascript - Angular:将数据绑定作为参数传递不起作用
- amazon-web-services - “强一致性”与“写后读一致性”
- c++ - 如何在现代 C++ 中将不同类类型的对象存储到一个容器中?