问题:我想在Qt项目中使用Android构建系统(版本3),但是此gradle版本(与旧版本2相比)会更改生成的输出{{1} }文件位于apk
下,而不是$buildDir/outputs/apk/debug
下(已添加$buildDir/outputs/apk
文件夹),但是当Qt Android工具包尝试将应用安装到Android设备时,它只会在旧位置查找,而无法找到apk文件。我使用Android Studio进行了检查,它表明Gradle 3正常工作
debug
新位置:
$build_folder/android-build\build\outputs\apk\my.apk
错误(编译):
adb:错误:无法统计 'D:/Qt/FireBase/build-client01-Android_for_armeabi_v7a_GCC_4_9_Qt_5_11_0_for_Android_armv73-Release/android-build//build/outputs/apk/android-build-debug.apk': 没有这样的文件或目录
仅当我更改了Qt生成的默认$build_folder/android-build\build\outputs\apk\debug\my.apk
并将gradle设置为版本3,默认生成的文件将build.gradle
设置为旧版本classpath
时,才会发生此问题>
旧:2.3.3
新:
classpath 'com.android.tools.build:gradle:2.3.3'
我还有其他更改,也需要更改classpath 'com.android.tools.build:gradle:3.1.0
,以下是更新的文件:
build.gradle
gradle-wrapper.properties
gradle-wrapper.properties
buildscript {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
//classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:4.0.1' // google-services plugin
classpath 'com.android.tools.build:gradle:3.1.0'
}
}
allprojects {
repositories {
jcenter()
//google() // Google's Maven repository
maven {
url "https://maven.google.com"
}
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
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!
*******************************************************/
compileSdkVersion androidCompileSdkVersion.toInteger()
buildToolsVersion androidBuildToolsVersion
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
}
}
dependencies {
// ...
//libfirebase_auth.a
//libfirebase_app.a
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation 'com.google.android.gms:play-services-base:15.0.1'
// Getting a "Could not find" error? Make sure you have
// added the Google maven respository to your root build.gradle
}
apply plugin: 'com.google.gms.google-services'
答案 0 :(得分:1)
我仍然不知道如何指示Qt在哪里以及如何指示新的输出结构,但是作为一种解决方法,我现在将配置添加到build.gradle
中,以复制所生成的apk
返回到~/apk
,Qt在其中寻找!
// make a copy of APK from "$buildDir/outputs/apk/debug" back to "$buildDir/outputs/apk"
def archiveBuildTypes = ["release", "debug"];
applicationVariants.all { variant ->
variant.outputs.all { output ->
if (variant.buildType.name in archiveBuildTypes) {
def taskSuffix = variant.name.capitalize()
def assembleTaskName = "assemble${taskSuffix}"
if (tasks.findByName(assembleTaskName)) {
def copyAPKFolderTask = tasks.create(name: "archive${taskSuffix}", type: org.gradle.api.tasks.Copy) {
description "copy APK to old folder"
def sourceFolder = "$buildDir/outputs/apk/$output.baseName"
def destinationFolder = "$buildDir/outputs/apk"
print "Copy apk from: $sourceFolder into $destinationFolder\n"
from(sourceFolder)
into destinationFolder
eachFile { file ->
file.path = file.name // so we have a "flat" copy
}
includeEmptyDirs = false
}
tasks[assembleTaskName].finalizedBy = [copyAPKFolderTask]
}
}
}
}
更新:
gradle 3.1.x
和更高版本至少需要androidBuildToolsVersion 27
,而Qt当前不支持高于androidBuildToolsVersion 26
,因此实际上退回到支持构建工具的gradle 3.0.x
可能更安全26 < p>
甚至有可能退回到gradle 2.3.3
(对于compile
和任何必需的模块,使用implementation
而不是FireBase
:
compile 'com.google.firebase:firebase-core:16.0.1'
...
答案 1 :(得分:1)
我在build.gradle上使用它:
android {
...
applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "../" + outputFileName
}
}
}