插件:https://pub.flutter-io.cn/packages/amap_base
參考簽名keystore:https://blog.csdn.net/weixin_44567104/article/details/90377912
參考解決用戶key不正確或過期,md5不正確問題:https://blog.csdn.net/m00123456789/article/details/71404282?tdsourcetag=s_pctim_aiomsg
amap_base算是評分比較高的,但作者比較忙一直沒更新問題也比較多
1、生成keystore文件,放到根目錄下。參考https://blog.csdn.net/weixin_44567104/article/details/90377912
2、生成keystore.properties文件,加入配置
storePassword=xxx keyPassword=xxx keyAlias=xxx #這里是app下的build.gradle加載,android.keystore在上級目錄,就是根目錄 storeFile=../android.keystore
3、app下的build.gradle加入配置
// load keystore簽名配置,地圖、支付等服務都要用到 def keystorePropertiesFile = rootProject.file("keystore.properties") def keystoreProperties = new Properties() keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) android { ... //簽名配置 signingConfigs { debug { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile file(keystoreProperties['storeFile']) storePassword keystoreProperties['storePassword'] } release { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile file(keystoreProperties['storeFile']) storePassword keystoreProperties['storePassword'] } } buildTypes { profile { initWith debug } debug { signingConfig signingConfigs.debug } 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.release } } }
4、修改AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <!--包名必須和build.gradle里的applicationId一致--> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="xxx"> <!-- 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.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.CAMERA" /> <!-- 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="flutter_module" android:icon="@mipmap/ic_launcher"> <!--android配置amap key,ios在初始化的時候傳入AMap.init('ioskey')--> <meta-data android:name="com.amap.api.v2.apikey" android:value="key" /> <!--改包名后這里默認.MainActivity會找不到--> <activity android:name="com.example.flutter_module.host.MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" 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> </application> </manifest>
5、一些問題,基本都是驗簽沒過,sha1和packagename一定要對應上,android工程配置也要一致。用戶key不正確一般加上keystore驗簽就行了,md5不正確應該是包名不匹配