Flutter添加谷歌登录后调试安装报错INSTALL_FAILED_INVALID_APK,求解决
添加「使用谷歌继续登录」功能后,调试构建时出现APK安装失败,报错信息如下:
Launching lib/main.dart on sdk gphone16k arm64 in debug mode...
Running Gradle task 'assembleDebug'...
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
✓ Built build/app/outputs/flutter-apk/app-debug.apk
Installing build/app/outputs/flutter-apk/app-debug.apk...
Error: ADB exited with exit code 1
Performing Streamed Installadb: failed to install /Users/username/{Project Path}/build/app/outputs/flutter-apk/app-debug.apk: Failure [INSTALL_FAILED_INVALID_APK: INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2]
Error launching application on sdk gphone16k arm64.
以下是解决步骤:
- 打开
android/app/src/main/AndroidManifest.xml,在<application>标签中添加android:extractNativeLibs="true":<application android:name="${applicationName}" android:icon="@mipmap/ic_launcher" android:label="your_app_name" android:extractNativeLibs="true"> - 清理项目缓存:
flutter clean cd android && ./gradlew clean cd .. - 重新构建并运行:
flutter run
这个错误多是因为谷歌登录依赖引入的原生库无法被系统正确提取,开启extractNativeLibs可强制系统提取原生库,配合清理缓存能消除依赖冲突或旧缓存导致的异常。
内容的提问来源于stack exchange,提问作者Ahammed Nibras

