Exclude a source file from source set in gradle build - android

Created a bare-bone Empty Activity sample app in Android Studio. Tried multiple ways but unable to exclude a file. App launches normally while I expect it should not have worked.
android {
compileSdk 31
defaultConfig {
applicationId "com.example.myapp"
minSdk 23
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
sourceSets {
debug {
//java.exclude("src/main/java/com/example/myapp/MainActivity.kt")
java {
exclude "**/*.kt"
}
kotlin {
exclude "**/*.kt"
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
Anything wrong with sourceset config?

Related

Cannot find a variant matching build type 'debug' and product flavors '[]' in :app

build.gradle module
`
android {
namespace 'com.bangkit.booking_futsal'
compileSdk 32
defaultConfig {
applicationId "com.bangkit.booking_futsal"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
buildscript {
repositories {
maven { url "http://dl.bintray.com/pt-midtrans/maven" }
maven { url "https://jitpack.io" }
}
}
productFlavors {
sandbox {
buildConfigField "String", "BASE_URL", "\"BASE_URL\""
buildConfigField "String", "CLIENT_KEY", "\"CLIENT_KEY\""
}
}
}`
i added buildscript and productFlavors in gradle module, but it generates error as shown below.
[error(https://i.stack.imgur.com/dNlHG.png)
Cannot find a variant matching build type 'debug' and product flavors
'[]' in :app
here I use kotlin and android studio dolphin
I expect no errors when syncing the project

Android wear application from targetSDk 28 to 30

I m upgrading my Android wear project using Android Studio.
So I change the follow code:
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.medicinanucleare.cardio"
minSdkVersion 26
targetSdkVersion 28
versionCode 4
versionName "1.3"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
}
with this:
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.medicinanucleare.cardio"
minSdkVersion 26
targetSdkVersion 30
versionCode 4
versionName "1.3"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
}
as you can see I change the targetSdkVersion from 28 to 30.
But now I have some errore on build.gradle file:
implementation 'com.android.support:percent-v4:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:wear:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
these lines are not recognized. I try also to comment the code but I have this error while I try to compile the application:
java.lang.RuntimeException: Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.3.2-runtime.jar (androidx.core:core:1.3.2) and support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0)
I try also to migrande application to Androidx but the operation failed.

"compileSdkVersion is not specified. Please add it to build.gradle.", although I have "compileSdk"

I have in app level build.gradle this, why gradle doesn't recognize shorter version of compileSdkVersion?
android {
compileSdk 32
defaultConfig {
applicationId "androidx.car.app.sample.helloworld"
minSdkVersion 29
targetSdkVersion 32
versionCode 1
versionName "1.0"
}
buildTypes {
release {
// Enables code shrinking, obfuscation, and optimization.
minifyEnabled true
proguardFiles getDefaultProguardFile(
'proguard-android-optimize.txt'),
'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
}
namespace "androidx.car.app.sample.helloworld"
}

Android: Is there a way to generate an ".aab" file of my app without signature?

I tried the traditional generation of app bundle (.aab) without signature like we do for '.apk' using android studio menu option : Build >> Build bundle(s)/Apk(s) >> Build bundle(s).
Normally, it should generate an '.aab' file and the name of the file should contains the prefix 'unsigned' like in the '.apk' file generated in same way but it doesn't exists.
When I deliver this .aab file to my client, he say to me that the file is signed.
My Gradle file :
android {
compileSdkVersion compile_sdk_version
buildToolsVersion build_tools_version
defaultConfig {
applicationId "com.**"
minSdkVersion min_sdk_version
targetSdkVersion compile_sdk_version
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
renderscriptTargetApi min_sdk_version
renderscriptSupportModeEnabled true
dexOptions {
javaMaxHeapSize "4g"
}
}
kapt {
correctErrorTypes true
}
flavorDimensions "default"
productFlavors {
production {
dimension 'default'
versionCode rootProject.ext.version_code_production
versionName rootProject.ext.version_name_production
}
stagging {
dimension 'default'
versionCode rootProject.ext.version_code_stagging
versionName rootProject.ext.version_name_stagging
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
applicationIdSuffix ".debug"
}
qualif {
applicationIdSuffix ".re7"
}
}
compileOptions {
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
// Sets Java compatibility to Java 11
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
}
buildFeatures {
dataBinding true
viewBinding true
}
}
dependencies {
..
}
}
How should I generate one without signature ?
Note: in gradle, I eleminate every signature declaration.
gradlew bundleRelease
Make sure that signingConfig in release build type is commented out

java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex || Android

**
While runing the code I encounter this error "Unable to merge dex || Android in the android studio
This is basically use of map in the android application**
This is the Build.gradle code
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.npatel7.carparking"
minSdkVersion 24
targetSdkVersion 26
versionCode 1
versionName "image1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
repositories {
mavenCentral()
}
}
Please assist me

Categories

Resources