问题: Flutter plugin ls_camera_plugin引用了camera.aar文件, 在.aar文件中包含的各架构的.so动态库. 在最终的app中, 通过pubspec.yaml引入了ls_camera_plugin, 发现通过flutter build apk生成的.apk是包含.aar中的动态库的, 但通过AndroidStudio的debug/run按钮, 或assembleDebug生成的.apk, 是不包含.so动态库文件的.
解决方法:
1. 打开app和ls_camera_plugin的安卓工程.
2. 确保在ls_camera_plugin的根路径中包含的libs/camera.aar文件.
3. 在ls_camera_plugin的build.gradle中修改:
rootProject.allprojects {
repositories {
google()
jcenter()
maven {
url 'http://download.flutter.io'
}
flatDir { // 关键部分
dirs 'libs'
dirs project(':ls_camera_plugin').file('libs')
}
}
}
......................
dependencies {
implementation(name:'lscameralib', ext:'aar') // 关键部分
implementation 'androidx.annotation:annotation:1.1.0'
// api "io.flutter:flutter_embedding_debug:1.0.0-d1bc06f032f9d6c148ea6b96b48261d6f545004f"
}
4. 在app/build.gradle中修改:
android{
....
dependencies {
implementation project(':ls_camera_plugin')
}
}
5. 在app/settings.gradle中修改:
include ':app', ':ls_camera_plugin'
6. 如果遇到 "Program type already present" 的错误, 需要clean project再重新build. 如仍失败, 检查是否有重复的依赖