应用插件时出现错误:"com.huawei.agconnect" in Flutter



我试图在flutter中使用华为SDK,所以我在android/app/build.gradle文件,如中的说明所示https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/integrate-plugin-0000001050418527

apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
**apply plugin: 'com.huawei.agconnect'**

然而,它返回时出现错误:

FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app_settings:compileDebugAidl'.
> Failed to find Platform SDK with path: platforms;android-R

我看到了一些解决方案,其中指出需要在android/build.gradle文件中添加以下代码

subprojects {
project.evaluationDependsOn(':app')
}
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
afterEvaluate {project ->
if (project.hasProperty("android") && project.property("android").compileSdkVersion.equals("android-R")) {
android {
compileSdkVersion 30
}
}
}
}

我已经添加了它,但它仍然返回相同的错误。当我删除应用插件"com.huawei.agconnect">时,没有出现错误。但在这种情况下,我想使用插件,因为我正计划使用华为推送套件。

请告诉我是否需要任何额外的信息来解决这个问题。非常感谢。

与这里的github问题一样,错误很可能是由您使用的Android SDK版本引起的。华为Flutter推送套件建议您使用Android SDK 10.0(API 29级(或9.0(API 28级(版本。您可以通过导航到文件>从Android Studio下载这些版本;设置>安卓SDK>SDK平台菜单。

对于build.gradle,您可以将您的gradle文件与华为Flutter Push Kit-Demo中提供的文件进行比较,并进行必要的更改。为了方便起见,我将build.gradle文件留给huawei_push:5.0.2+301。

注意:如果这些操作不能解决错误,请向github存储库提交一个问题,并附上flutter医生输出、渐变文件和再现错误的最小代码样本。

android/build.gradle

buildscript {
repositories {
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.0'
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}

android/app/build.gradle

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.huawei.agconnect'
android {
compileSdkVersion 29
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
// The Application ID here should match with the Package Name on the AppGalleryConnect
applicationId "<package_name>"
minSdkVersion 17
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
signingConfigs {
config {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
debug {
signingConfig signingConfigs.config
}
release {
signingConfig signingConfigs.config
// Enables code shrinking, obfuscation and optimization for release builds
minifyEnabled true
// Unused resources will be removed, resources defined in the res/raw/keep.xml will be kept.
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
flutter {
source '../..'
}

最新更新