Flutter 存量Android接入Flutter躺坑指南

有思想,也有忧伤和理想,这才是生活。
人生没有如果,只有后果和结果。

前言

最近给一个老项目接入Flutter,遇到了一些问题,记录下。

存量Android接入Flutter官方文档:Integrate a Flutter module into your Android project

踩坑的本机环境

注意对比下我的环境和你的环境是否一样,有些问题在Flutter的新版本中已经被修复了。

➜  app git:(master) ✗ flutter --version
Flutter 1.9.1+hotfix.6 • channel stable • https://github.com/flutter/flutter.git
Framework • revision cc949a8e8b (3 weeks ago) • 2019-09-27 15:04:59 -0700
Engine • revision b863200c37
Tools • Dart 2.5.0

Flutter doctor -v

➜  app git:(master) ✗ flutter doctor -v                  
[] Flutter (Channel stable, v1.9.1+hotfix.4, on Mac OS X 10.15 19A583, locale en-CN)
    • Flutter version 1.9.1+hotfix.4 at /Users/.../flutter
    • Framework revision cc949a8e8b (3 weeks ago), 2019-09-27 15:04:59 -0700
    • Engine revision b863200c37
    • Dart version 2.5.0

 
[] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/notzuonotdied/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[] Xcode - develop for iOS and macOS (Xcode 11.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.1, Build version 11A1027
    • CocoaPods version 1.8.3

[] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 40.1.2
    • Dart plugin version 191.8423
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[!] IntelliJ IDEA Ultimate Edition (version 2019.2.3)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • For information about installing plugins, see
      https://flutter.dev/intellij-setup/#installing-the-plugins

[] VS Code (version 1.39.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.5.1

[] Connected device (1 available)
    • iPhone 11 Pro Max • 61AA9D21-B994-4FC5-9164-757EABF90190 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-1 (simulator)

! Doctor found issues in 1 category.

错误

升级JDK1.8

项目中接入了Tinker,且JDK版本为1.7。

接入Flutter需要升级项目JDK版本为1.8。

Java 8 language support, as requested by 'android.enableD8.desugaring= true' in your gradle.properties file, is not supported when 'android.useDexArchive= false'.

需要在项目根目录下的gradle.properties中增加以下的代码:

android.useDexArchive = true
# Java8语法脱糖
android.enableD8.desugaring = true

混淆带来的问题

Warning: io.flutter.embedding.android.FlutterView: can't find referenced method 'android.graphics.Insets getSystemGestureInsets()' in library class android.view.WindowInsets
Warning: io.flutter.embedding.android.FlutterView: can't find referenced class android.graphics.Insets
Warning: io.flutter.embedding.android.FlutterView: can't find referenced class android.graphics.Insets
Warning: io.flutter.embedding.android.FlutterView: can't find referenced class android.graphics.Insets
Warning: io.flutter.embedding.android.FlutterView: can't find referenced class android.graphics.Insets
Warning: io.flutter.embedding.android.FlutterView: can't find referenced class android.graphics.Insets
Warning: io.flutter.embedding.android.FlutterView: can't find referenced class android.graphics.Insets
Warning: io.flutter.view.FlutterView: can't find referenced method 'android.graphics.Insets getSystemGestureInsets()' in library class android.view.WindowInsets
Warning: io.flutter.view.FlutterView: can't find referenced class android.graphics.Insets
Warning: io.flutter.view.FlutterView: can't find referenced class android.graphics.Insets
Warning: io.flutter.view.FlutterView: can't find referenced class android.graphics.Insets
Warning: io.flutter.view.FlutterView: can't find referenced class android.graphics.Insets
Warning: io.flutter.view.FlutterView: can't find referenced class android.graphics.Insets
Warning: io.flutter.view.FlutterView: can't find referenced class android.graphics.Insets

proguard中增加-dontwarn android.**即可解决。

minSdkVersion

有些老项目支持到了14,所以需要做下处理。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="包名">

    <!--需要覆盖minSdk的部分-->
    <uses-sdk tools:overrideLibrary="com.example.xxx" />
</manifest>

EnclosingMember annotations

问题:Android studio warning - InnerClass annotations are missing corresponding EnclosingMember annotations

增加如下内容:

-keepattributes *Annotation*
-keep @**annotation** class * {*;} 

附录

D8相关

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值