Flutter运行踩坑记录

4,732 阅读3分钟

调用npm报错

flutter run报错 看了这篇文章提示说是node版本问题 blog.csdn.net/Xu_JL1997/a… 虽然不知道跟node有什么关系,还是试试

结果估计是装失败了,直接node运行不了了

报env: node: No such file or directory

根据这篇文章的提示,解决 blog.csdn.net/Xu_JL1997/a…

运行rm提示没权限,直接找到这个文件删掉

提示没有写权限

运行

sudo chown -R $(whoami):admin /usr/local

成功

Unable to 'pub upgrade' flutter tool.

解决方法:删除 flutter SDK中 bin/cache 文件夹,然后再flutter upgrade

Error: CocoaPods's specs repository is too out-of-date to satisfy dependencies.

这个问题是由于没有配置信任的服务器HTTPS验证。默认,cURL被设为不信任任何CAs,就是说,它不信任任何服务器验证。

只需要执行下面命令就可以解决

git config --global http.sslVerify false

更新pod

pod update --no-repo-update

Flutter开发iOS系统升级到iOS13后运行报错Device doesn't support wireless sync

网上的解决办法:

flutter channel dev
 
// 或下面
// flutter channel master
 
// 然后执行
flutter doctor

因为 dart2.6版本 flutter1.10版本之后支持iOS13系统

但我不太适用

切换dev后不报错了,能够成功运行,但运行app后黑屏...

尝试切换master后,flutter upgrade

切回stable后,flutter upgrade

重试一次可以了。。。

偶尔报错 不稳定 经常断开 且导致iphone死机 自动重启 已提issues: github.com/flutter/flu…

模拟器抓包

flutter run卡住不动

➜  vpmaxx-app git:(test) flutter run
Launching lib/main.dart on iPhone Xʀ in debug mode...
Running Xcode build...                                                  
                                                   
Xcode build done.                                           51.8s

卡住不动半个小时都走不下去

尝试:

flutter clean

flutter run

可以解决

升级系统后Error running pod install

升级macOs10.15.2后运行报错:

vpmaxx-app git:(test) flutter run
 
Launching lib/main.dart on iPhone 11 Pro Max in debug mode...
 
Running pod install...                                              0.0s
Error output from CocoaPods:
↳
    /usr/local/bin/pod: /usr/local/Cellar/cocoapods/1.7.5/libexec/bin/pod: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby: bad interpreter: No
    such file or directory
    /usr/local/bin/pod: line 2: /usr/local/Cellar/cocoapods/1.7.5/libexec/bin/pod: Undefined error: 0

Error running pod install
Error launching application on iPhone 11 Pro Max.

重装cocoapods

sudo gem install cocoapods

再进ios目录

pod install

Waiting for another flutter command to release the startup lock

  1. 打开flutter的安装目录/bin/cache/
  2. 删除lockfile文件

ERROR: The specified language version is too high. The highest supported language version is **

尝试

flutter clean

Package install error: Failure [INSTALL_FAILED_OLDER_SDK] Error launching application on Samsung.

修改xstore-pda-app-frontend/android/app/build.gradle文件 minSdk:19, targetSdk:32 为合适的值

D8: Cannot fit requested classes in a single dex file (# methods: 84339 > 65536 ; # fields: 72421 > 65536)

D8: Cannot fit requested classes in a single dex file (# methods: 84339 > 65536 ; # fields: 72421 > 65536) com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: The number of method references in a .dex file cannot exceed 64K.

解决方案参考: developer.android.com/tools/build…

  1. 修改模块级 build.gradle 文件以启用 MultiDex,并将 MultiDex 库添加为依赖项
android {
    defaultConfig {
        ...
        minSdkVersion 15
        targetSdkVersion 28
        multiDexEnabled true
    }
    ...
}

dependencies {
    implementation "androidx.multidex:multidex:2.0.1" 
}

2. 请修改清单文件以设置 <application> 标记中的 android:name

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
    <application
            android:name="androidx.multidex.MultiDexApplication"  >
        ...
    </application>
</manifest>

# The operation couldn’t be completed. Unable to locate a Java Runtime.

java -version检查是否安装JDK,没有则去安装 www.jianshu.com/p/57422f638…

Exception: Gradle task assembleDebug failed with exit code 1

  1. 检查build.gradle文件中的错误,比如缺少某些依赖库或者配置错误。

  2. 清理项目,重新编译。

  3. 重新同步gradle文件。

  4. 检查是否有重复的依赖库,如果有,删除重复的依赖库。

  5. 检查是否有冲突的依赖库,如果有,尝试更新依赖库的版本。

  6. 尝试重新安装Android Studio。

找不到.g.dart文件

flutter pub run build_runner build --delete-conflicting-outputs

Using insecure protocols with repositories, without explicit opt-in, is unsupported

                                                                        
FAILURE: Build failed with an exception.                                
                                                                        
* What went wrong:                                                      
A problem occurred configuring project ':vcsp_account'.                 
> Could not resolve all dependencies for configuration ':vcsp_account:classpath'.
   > Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven repository 'maven(http://mvn1.tools.vipshop.com/nexus/content/repositories/releases/)' to redirect to a secure protocol (like HTTPS) or allow insecure protocols. See https://docs.gradle.org/7.2/dsl/org.gradle.api.artifacts.repositories.UrlArtifactRepository.html#org.gradle.api.artifacts.repositories.UrlArtifactRepository:allowInsecureProtocol for more details. 
> Could not get unknown property 'android' for project ':vcsp_account' of type org.gradle.api.Project.
                                                                        
* Try:                                                                  
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
                                                                        
* Get more help at https://help.gradle.org      

原因:新版gradle不支持http链接下载maven

解决方法: 在maven配置时加上属性 allowInsecureProtocol

repositories { 
    maven { 
        allowInsecureProtocol = true 
        url 'http://...'
    } 
}