I am not a developer. I did this for fun, but I haven't touched code for several years now, and I've forgotten all about the principles. so please, keep it simple, and tell me what to do precisely
I created an unpretentious application, which we use as a family, and which I put on the play store for a practical purpose, and in case it might interest someone. Today, I have to update API level from 33 to 34 (asked by google).
I'm used to create apk with ./gradlew assembleRelease
and the bundle with ./gradlew bundleRelease
All seems to work normally for the apk, but error for the bundle:
BUILD SUCCESSFUL in 6s
75 actionable tasks: 2 executed, 73 up-to-date
FAILURE: Build failed with an exception.
* Where:
Build file '/ssd/chris/AndroidStudioProjects/MyApp/app/build.gradle' line: 183
* What went wrong:
Could not determine the dependencies of task ':app:bundleRelease'.
> Could not create task ':app:bundleDemoRelease'.
> DefaultTaskContainer#register(String, Action) on task set cannot be executed in the current context.
* 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 484ms
Do I need to change somthing in build or the method to create bundle please?
app/build.gradle:
apply plugin: 'com.android.application'
android {
compileSdk 34
signingConfigs {
release {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
// Optional, specify signing versions used
v1SigningEnabled true
v2SigningEnabled true
}
}
defaultConfig {
applicationId "fr.myapp"
minSdkVersion 22
targetSdkVersion 34
versionCode 260
versionName '2.6.0'
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
vectorDrawables.useSupportLibrary = true
signingConfig signingConfigs.release
}
buildFeatures {
buildConfig = true
}
buildTypes {
debug {
buildConfigField "String", "VARIANT", "\"dev\""
buildConfigField "boolean", "DEV", "true"
}
release {
buildConfigField "String", "VARIANT", "\"\""
buildConfigField "boolean", "DEV", "false"
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
android.applicationVariants.all { variant ->
def appName
//Check if an applicationName property is supplied; if not use the name of the parent project.
if (project.hasProperty("applicationName")) {
appName = applicationName
} else {
appName = parent.name
}
variant.outputs.all { output ->
outputFileName = "${appName}-${variant.versionName}.apk"
}
}
}
}
productFlavors {
demo {
applicationId "fr.myappdemo"
versionNameSuffix '-demo'
}
full {
}
}
compileOptions {
targetCompatibility = 1.8
sourceCompatibility = 1.8
}
packagingOptions {
resources {
excludes += ['META-INF/LICENSE.md', 'META-INF/NOTICE.md']
}
}
namespace 'fr.myapp'
flavorDimensions += 'app'
}
dependencies {
modules {
module("org.jetbrains.kotlin:kotlin-stdlib-jdk7") {
replacedBy("org.jetbrains.kotlin:kotlin-stdlib", "kotlin-stdlib-jdk7 is now part of kotlin-stdlib")
}
module("org.jetbrains.kotlin:kotlin-stdlib-jdk8") {
replacedBy("org.jetbrains.kotlin:kotlin-stdlib", "kotlin-stdlib-jdk8 is now part of kotlin-stdlib")
}
}
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation 'androidx.preference:preference:1.2.1'
implementation 'org.droidparts:droidparts-misc:3.2.5'
implementation 'joda-time:joda-time:2.12.5'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.gms:play-services-vision:20.1.3'
//noinspection GradleDependency
implementation 'com.google.android.material:material:1.9.0'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.sun.mail:android-mail:1.6.7'
implementation 'com.sun.mail:android-activation:1.6.7'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'androidx.annotation:annotation:1.8.0'
implementation 'com.github.yalantis:ucrop:2.2.6'
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
configurations {
configureEach {
exclude group: 'androidx.lifecycle', module: 'lifecycle-viewmodel-ktx'
}
}
static String firstMatchingSubstring(String taskName, String[] keys) {
def lcName = taskName.toLowerCase()
for(String key: keys) { if(lcName.contains(key.toLowerCase())) return key }
return null
}
/**
*
* @param taskName e.g., bundleMyFlavorRelease or bundleRelease
* @return
*/
String getBuildType(String taskName) {
return firstMatchingSubstring(taskName, getBuildTypeNames())
}
/**
*
* @param taskName e.g., bundleMyFlavorRelease
* @return
*/
String getFlavor(String taskName) {
return firstMatchingSubstring(taskName, getProductFlavorNames())
}
String[] getBuildTypeNames() {
def types = []
android.buildTypes.configureEach { type -> types.add(type.name) }
return types
}
String[] getProductFlavorNames() {
def flavors = []
android.productFlavors.configureEach { flavor -> flavors.add(flavor.name) }
return flavors
}
tasks.configureEach { task ->
def name = task.name
//Skip some unnecessary tasks
if (name.startsWith("bundle")
&& !name.contains("Classes")
&& !name.contains("Resources")
&& name != "bundle") {
def renameTaskName = "rename${task.name.capitalize()}Aab"
def version = "${android.defaultConfig.versionName}"
def flavor = getFlavor(name)
def type = getBuildType(name)
if(flavor == null || type == null) return
def outputName
if (flavor == "full")
outputName = "MyApp-$version"
else
outputName = "MyApp-$version-$flavor"
tasks.register(renameTaskName) {
def path = "${rootDir}/app/${flavor}/${type}/"
def originalFile = "$path/app-${flavor}-${type}.aab"
doLast {
if (file("$originalFile").exists()) {
ant.move file: "$originalFile",
tofile: "$path/${outputName}.aab"
}
}
}
task.finalizedBy(renameTaskName)
}
}
project.afterEvaluate
to ensure that the tasks are registered after the project is evaluated.project.afterEvaluate { android.applicationVariants.all { variant ->
and here alsotasks.configureEach { task -> def name = task.name //Skip some unnecessary tasks