Android studio版本:
flutter版本:2.10.5
Java版本:Java8
一、创建一个Android工程
这里就不说了
flutter create -t module --org com.example my_flutter
这里就创建了一个名字为my_flutter的工程了,使用命令flutter run运行一下,它是能跑起来的。
在setting.gradle中,配置module,加入
include ':my_flutter'
setBinding(new Binding([gradle: this]))
evaluate(new File(
settingsDir,
'my_flutter/.android/include_flutter.groovy'
)
)
这里的路径“my_flutter/.android/include_flutter.groovy”是一个相对路径,my_flutter是我们创建的flutter工程,路径不要填错了。
还要继续改一下dependencyResolutionManagement,原来是
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
repositories {
google()
mavenCentral()
}
}
改为
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS) // edit this
repositories {
google()
mavenCentral()
String flutterStorageUrl = System.getenv("FLUTTER_STORAGE_BASE_URL") ?: "https://storage.googleapis.com"
maven {
url flutterStorageUrl + "/download.flutter.io"
}
}
}
最后在app/build.gradle中加入flutter module依赖
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation project(path: ':flutter')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
细心的你可能注意到了,我们的flutter module名字不是my_flutter吗,怎么这里是flutter了,其实这个我也不清楚,如果写成my_flutter的话会有找不到的错误,最好的办法是点击 File -> project structure -> Dependencies手动的加进去。
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- hzar.cn 版权所有 赣ICP备2024042791号-5
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务