[英]Build error when trying to add Firebase dependency to Qt project
I would like to use Firebase
the same way as in any native Android
app non using Qt
(ie using Java
).我想以与不使用
Firebase
的任何本机Android
应用程序(即使用Java
)相同的方式使用Qt
。 I'm already have one (all is working fine).我已经有了一个(一切正常)。
Now I'm trying to add Firebase
to my existing Qt
project.现在我正在尝试将
Firebase
添加到我现有的Qt
项目中。 For now, I'm trying to add all the required dependencies to build.gradle
(so I can use Firebase APIs
in my Java
source code part of my Qt
project), and getting weird errors.现在,我正在尝试将所有必需的依赖项添加到
build.gradle
(这样我就可以在我的Qt
项目的Java
源代码部分中使用Firebase APIs
),并出现奇怪的错误。
I'm not good in Gradle
so any help is appreciated (if this is possible at all, because I'm using quite old Qt 5.12.12
).我在
Gradle
,因此感谢任何帮助(如果可能的话,因为我使用的是相当旧的Qt 5.12.12
)。
This is build.gradle
I have (builds and runs fine):这是我拥有的
build.gradle
(构建并运行良好):
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
}
}
repositories {
google()
jcenter()
}
apply plugin: 'com.android.application'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.google.code.gson:gson:2.7'
implementation 'com.jakewharton:process-phoenix:2.1.2' // https://github.com/JakeWharton/ProcessPhoenix
implementation 'me.dm7.barcodescanner:zxing:1.9.13' // https://github.com/dm77/barcodescanner
}
android {
/*******************************************************
* The following variables:
* - androidBuildToolsVersion,
* - androidCompileSdkVersion
* - qt5AndroidDir - holds the path to qt android files
* needed to build any Qt application
* on Android.
*
* are defined in gradle.properties file. This file is
* updated by QtCreator and androiddeployqt tools.
* Changing them manually might break the compilation!
*******************************************************/
// Buggy thing: fails to build. Needs to be replaced with actual numbers.
// https://stackoverflow.com/a/46290586/3765267
/*compileSdkVersion androidCompileSdkVersion.toInteger()
buildToolsVersion androidBuildToolsVersion*/
compileSdkVersion 30
buildToolsVersion "30.0.2"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java']
aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl']
res.srcDirs = [qt5AndroidDir + '/res', 'res']
resources.srcDirs = ['src']
renderscript.srcDirs = ['src']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
}
lintOptions {
abortOnError false
}
}
This is build.gradle
with all the dependencies I try to add (I've added classpath 'com.google.gms:google-services:4.3.14'
to dependencies
section and apply plugin: 'com.google.gms.google-services'
line):这是
build.gradle
,其中包含我尝试添加的所有依赖项(我已将classpath 'com.google.gms:google-services:4.3.14'
添加到dependencies
项部分并apply plugin: 'com.google.gms.google-services'
线):
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.google.gms:google-services:4.3.14'
}
}
repositories {
google()
jcenter()
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.google.code.gson:gson:2.7'
implementation 'com.jakewharton:process-phoenix:2.1.2' // https://github.com/JakeWharton/ProcessPhoenix
implementation 'me.dm7.barcodescanner:zxing:1.9.13' // https://github.com/dm77/barcodescanner
}
android {
/*******************************************************
* The following variables:
* - androidBuildToolsVersion,
* - androidCompileSdkVersion
* - qt5AndroidDir - holds the path to qt android files
* needed to build any Qt application
* on Android.
*
* are defined in gradle.properties file. This file is
* updated by QtCreator and androiddeployqt tools.
* Changing them manually might break the compilation!
*******************************************************/
// Buggy thing: fails to build. Needs to be replaced with actual numbers.
// https://stackoverflow.com/a/46290586/3765267
/*compileSdkVersion androidCompileSdkVersion.toInteger()
buildToolsVersion androidBuildToolsVersion*/
compileSdkVersion 30
buildToolsVersion "30.0.2"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java']
aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl']
res.srcDirs = [qt5AndroidDir + '/res', 'res']
resources.srcDirs = ['src']
renderscript.srcDirs = ['src']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
}
lintOptions {
abortOnError false
}
}
And now I'm getting the following weird error trying to build the project:现在我在尝试构建项目时遇到以下奇怪的错误:
Generating Android Package
Input file: C:/Work/Source/build-fdm-Android_Qt_5_12_12_Clang_armeabi_v7a-Debug/ui/android-libfdm.so-deployment-settings.json
Output directory: C:/Work/Source/build-fdm-Android_Qt_5_12_12_Clang_armeabi_v7a-Debug/ui/android-build/
Application binary: C:/Work/Source/build-fdm-Android_Qt_5_12_12_Clang_armeabi_v7a-Debug/bin/libfdm.so
Android build platform: android-33
Install to device: No
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Work\Source\build-fdm-Android_Qt_5_12_12_Clang_armeabi_v7a-Debug\ui\android-build\build.gradle' line: 18
* What went wrong:
A problem occurred evaluating root project 'android-build'.
> ASCII
* 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
BUILD FAILED in 3s
Addition #1.添加#1。 I can build using Qt 6.4.1 + Firebase. The question is about Qt 5.12.12.
我可以使用 Qt 6.4.1 + Firebase 进行构建。问题是关于 Qt 5.12.12。 I suspect the reason is too old Gradle version it's using (4.6) or something like that.
我怀疑原因是它使用的 Gradle 版本太旧 (4.6) 或类似版本。
By default in android we declare the plugin dependencies in gradle root module.默认情况下,在 android 中,我们在 gradle 根模块中声明插件依赖项。 Seems like in qt project we have only one flat layer with only one
build.gradle
file.似乎在 qt 项目中我们只有一个平面层,只有一个
build.gradle
文件。 The good news is that we can declare plugin dependencies in settings.gradle
as well好消息是我们也可以在
settings.gradle
中声明插件依赖
Make sure you connected the plugin in settings.gradle
:确保您在
settings.gradle
中连接了插件:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.google.gms.google-services' version '4.3.10' apply false
}
}
now you can apply the plugins in build.gradle
like this:现在您可以像这样在
build.gradle
中应用插件:
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
android { ... }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.