Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not generate apk when buildType is not 'release' #25

Open
lz233 opened this issue Aug 14, 2022 · 3 comments
Open

Can not generate apk when buildType is not 'release' #25

lz233 opened this issue Aug 14, 2022 · 3 comments

Comments

@lz233
Copy link

lz233 commented Aug 14, 2022

buildTypes and dependencies:

android {
    ...
    defaultConfig {
        ...
    }
    buildTypes {
        release {
            minifyEnabled true
            zipAlignEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        google {
            minifyEnabled true
            zipAlignEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        ...
    }
    kotlinOptions {
        ...
    }
    buildFeatures {
        ...
    }
    packagingOptions {
        ...
    }
}
configurations.all {
    exclude group: 'dev.rikka.rikkax.appcompat', module: 'appcompat'
}
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.5.0'
    implementation 'androidx.core:core-ktx:1.8.0'
    implementation 'androidx.room:room-runtime:2.4.3'
    implementation 'androidx.viewpager2:viewpager2:1.1.0-beta01'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.preference:preference:1.2.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
    kapt 'androidx.room:room-compiler:2.4.3'

    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'

    implementation 'com.microsoft.appcenter:appcenter-analytics:4.4.5'
    implementation 'com.microsoft.appcenter:appcenter-crashes:4.4.5'

    //implementation 'dev.rikka.rikkax.appcompat:appcompat:1.5.0'
    //implementation 'dev.rikka.rikkax.material:material:2.5.1'
    implementation "dev.rikka.rikkax.material:material-preference:2.0.0"

    implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.9'
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

    compileOnly 'de.robv.android.xposed:api:82'

    implementation 'org.lsposed.hiddenapibypass:hiddenapibypass:4.3'

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

image

and when I try to generate a apk file typed google, gradle occur a failure:
message.log

@Fox2Code
Copy link
Contributor

You should not use buildTypes to make different builds types, use productFlavors property instead.
Only debug and release should exists inside buildTypes.

Example of possible fix:

android {
    [...]
    buildTypes {
        release {
            minifyEnabled true
            zipAlignEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug {
            applicationIdSuffix '.debug'
            debuggable true
        }
    }
    flavorDimensions "type"
    productFlavors {
        "default" {
            dimension "type"
            buildConfigField "boolean", "IS_GOOGLE", "false"
        }

        fdroid {
            dimension "type"
            applicationIdSuffix ".google"
            buildConfigField "boolean", "IS_GOOGLE", "true"
        }
    }
    [...]
}

The buildConfigField should make BuildConfig.IS_GOOGLE be true or false depending on build type.
And applicationIdSuffix ".google" allow to install all variants of your app on the same device.

@mth141
Copy link

mth141 commented Oct 28, 2022

buildTypes and dependencies:

android {
    ...
    defaultConfig {
        ...
    }
    buildTypes {
        release {
            minifyEnabled true
            zipAlignEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        google {
            minifyEnabled true
            zipAlignEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        ...
    }
    kotlinOptions {
        ...
    }
    buildFeatures {
        ...
    }
    packagingOptions {
        ...
    }
}
configurations.all {
    exclude group: 'dev.rikka.rikkax.appcompat', module: 'appcompat'
}
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.5.0'
    implementation 'androidx.core:core-ktx:1.8.0'
    implementation 'androidx.room:room-runtime:2.4.3'
    implementation 'androidx.viewpager2:viewpager2:1.1.0-beta01'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.preference:preference:1.2.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
    kapt 'androidx.room:room-compiler:2.4.3'

    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'

    implementation 'com.microsoft.appcenter:appcenter-analytics:4.4.5'
    implementation 'com.microsoft.appcenter:appcenter-crashes:4.4.5'

    //implementation 'dev.rikka.rikkax.appcompat:appcompat:1.5.0'
    //implementation 'dev.rikka.rikkax.material:material:2.5.1'
    implementation "dev.rikka.rikkax.material:material-preference:2.0.0"

    implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.9'
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

    compileOnly 'de.robv.android.xposed:api:82'

    implementation 'org.lsposed.hiddenapibypass:hiddenapibypass:4.3'

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
image

and when I try to generate a apk file typed google, gradle occur a failure:
message.log

@lz233
Copy link
Author

lz233 commented Oct 28, 2022

You should not use buildTypes to make different builds types, use productFlavors property instead. Only debug and release should exists inside buildTypes.

Example of possible fix:

android {
    [...]
    buildTypes {
        release {
            minifyEnabled true
            zipAlignEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug {
            applicationIdSuffix '.debug'
            debuggable true
        }
    }
    flavorDimensions "type"
    productFlavors {
        "default" {
            dimension "type"
            buildConfigField "boolean", "IS_GOOGLE", "false"
        }

        fdroid {
            dimension "type"
            applicationIdSuffix ".google"
            buildConfigField "boolean", "IS_GOOGLE", "true"
        }
    }
    [...]
}

The buildConfigField should make BuildConfig.IS_GOOGLE be true or false depending on build type. And applicationIdSuffix ".google" allow to install all variants of your app on the same device.

This is a possible resolution.

But if I remove rikkaX, there is no error reported. Why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants