Flutter踩坑記(Android篇)

1. mac 無法打開“idevice_id”。
解決辦法:系統偏好設置-安全性與隱私-信任。

2. Could not find an option named "androidx"
AS 創建Flutter項目報上面錯誤信息,可能因爲flutter sdk 版本過低。
FlutterSDK下載地址
https://flutter.dev/docs/development/tools/sdk/releases?tab=macos

3. Mac環境下Android Studio 無法連接iOS模擬器
在mac環境下用Android Studio 寫Flutter,可以啓動iOS 模擬器,但是在設備列表裏找不到模擬器時
打開終端並輸入下面命令:
sudo xcode-select --switch/Applications/Xcode.app/Contents/Developer
之後回車,輸入本機密碼,就可以了

4. Your app isn’t using AndroidX
android gradle.properties下添加

android.enableJetifier=true
android.useAndroidX=true

5. bottom overflowed by 94 pixels
Scaffold下添加如下配置:resizeToAvoidBottomInset: false
原因:防止軟鍵盤彈出時遮擋頁面的東西。當設置爲 true 的時候,軟鍵盤彈出頁面會自動調整尺寸避免遮擋; 當爲 false 的時候則軟鍵盤彈出不會自動調整尺寸。該屬性值默認爲 true。

6. 啓動黑屏
Flutter項目啓動過程:
1、顯示android啓動項activity
2、flutter啓動項activity
3、進入flutter項目的第一個頁面
黑屏對應的是flutter啓動項activity
解決方案:
AndroidManifest.xml中目標activity下加入

    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="swift_rabbit"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>

            <!--Flutter 閃屏頁-->
            <meta-data
                android:name="io.flutter.embedding.android.SplashScreenDrawable"
                android:resource="@drawable/launch_background" />
            <!--閃屏頁結束後的Theme-->
            <meta-data
                android:name="io.flutter.embedding.android.NormalTheme"
                android:resource="@style/NormalTheme" />
        </activity>

        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>

style.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <!-- Show a splash screen on the activity. Automatically removed when
             Flutter draws its first frame -->
        <item name="android:windowBackground">@drawable/launch_background</item>
    </style>
    <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <item name="android:windowBackground">@drawable/normal_background</item>
    </style>
</resources>

normal_background.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white" />

    <!-- You can insert your own image assets here -->
    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/naruto" />
    </item>
</layer-list>

7. Flutter: Exception in thread “main” java.util.zip.ZipException:
error in opening zip file

修改android gradle版本build.gradle / gradle-wrapper.properties

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章