I'm using the android studios IDE, SDK version 32, build tools 33, and java version 1.8
I keep getting the error
Cannot resolve symbol 'File'
And actually the gradle syncs somehow and the file is created, but I need to solve the error
This is the settings gradle:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven {
url "https://dl.cloudsmith.io/public/cometchat/cometchat-pro-android/maven/"
}
}
}
rootProject.name = "ViegerT2"
include ':app'
include ':uikit'
project(':uikit').projectDir = new File(rootDir, 'android-java-chat-ui-
kit/uikit/')
This is the project gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
This is the APP gradle:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.viegert2"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
manifestPlaceholders = [file_provider: "ViagerT2"]
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
}
packagingOptions {
exclude 'META-INF/proguard/androidx-annotations.pro'
exclude 'META-INF/androidx.cardview_cardview.version'
}
buildToolsVersion '33.0.0'
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.annotation:annotation:1.4.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
//noinspection GradleCompatible
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
apply plugin: 'kotlin-android-extensions'
//implementation 'androidx.core:core-ktx:1.3.2'
//implementation 'androidx.appcompat:appcompat:1.3.1'
//implementation 'com.google.android.material:material:1.4.0'
//implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation platform('com.google.firebase:firebase-bom:29.0.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.google.firebase:firebase-database-ktx'
implementation 'com.google.firebase:firebase-storage-ktx'
implementation 'com.cometchat:pro-android-chat-sdk:3.0.0'
implementation 'com.cometchat:pro-android-calls-sdk:2.1.0'
implementation "androidx.recyclerview:recyclerview:1.2.1"
implementation 'com.github.bumptech.glide:glide:4.12.0'
//implementation project(path: ':uikit-kotlin')
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
implementation project(path: ':uikit')
}
And I also have this module gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 30
defaultConfig {
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "3.0.9-1"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
renderscriptSupportModeEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
ndk {
abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java', '.apt_generated']
aidl.srcDirs = ['src/main/aidl', '.apt_generated']
res.srcDirs = [
'src/main/res',
'src/main/res-components',
'src/main/res-components/calls',
'src/main/res-components/chats',
'src/main/res-components/cometchatui',
'src/main/res-components/groups',
'src/main/res-components/messagebubbles',
'src/main/res-components/messages',
'src/main/res-components/others',
'src/main/res-components/shared',
'src/main/res-components/userprofile',
'src/main/res-components/users'
]
}
}
dataBinding {
enabled = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion = '28.0.3'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.preference:preference:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//RecyclerView
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.emoji:emoji:1.1.0-rc01'
implementation 'androidx.emoji:emoji-bundled:1.1.0'
implementation 'androidx.emoji:emoji-appcompat:1.0.0'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation 'com.google.android.material:material:1.2.0-alpha04'
implementation 'com.facebook.shimmer:shimmer:0.4.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
//cometchat
compileOnly 'com.cometchat:pro-android-chat-sdk:3.0.9'
compileOnly 'com.cometchat:pro-android-calls-sdk:2.2.0'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.0'
}
Related
I am trying to add navigation library in android studio but fails to add here is my build.gradle(app)
plugins {
id 'com.android.application'
}
android {
compileSdk 33
defaultConfig {
applicationId "com.example.practice_8"
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
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
implementation 'androidx.navigation:navigation-fragment:2.5.1'
implementation 'androidx.navigation:navigation-ui:2.5.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Try this
In your app/gradle, add
plugins {
id 'com.android.application'
id 'androidx.navigation.safeargs'
}
def nav_version = "2.5.1"
inside dependency{ } add
// Kotlin
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
in project/gradle add
buildscript {
repositories {
google()
}
dependencies {
def nav_version = "2.5.1"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}
}
and sync your gradle
Here is reference
Android Nav
I am getting this error while running the app.
Here are the Gradle files for my project.
build.gradle
buildscript {
ext.kotlin_version = '1.3.20'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(app)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
signingConfigs {
'release' {
storeFile file('/Users/jeetraval/Documents/Workspace/my-audio-app-android/test.jks')
keyAlias 'key0'
storePassword 'Test#123'
keyPassword 'Test#123'
}
}
compileSdkVersion 31
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.jeet.myaudio"
minSdkVersion 25
targetSdkVersion 31
versionCode 5
// testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true
signingConfig signingConfigs.release
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled false
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
/*applicationVariants.all { variant ->
renameAPK(variant)
}*/
}
}
dataBinding {
enabled = true
}
dexOptions {
preDexLibraries = false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
flavorDimensions "default"
productFlavors {
prod {
versionName "1.0.3"
resValue "string", "app_name", "MyAudio"
}
}
}
dependencies {
// implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//noinspection GradleCompatible
implementation 'androidx.appcompat:appcompat:1.4.1'
//noinspection GradleCompatible
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.google.android.gms:play-services-location:19.0.1'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:retrofit:2.6.0'
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'io.reactivex.rxjava2:rxjava:2.1.16'
implementation 'com.skyfishjy.ripplebackground:library:1.0.1'
//noinspection GradleCompatible
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'cn.carbs.android:AvatarImageView:1.0.4'
// testImplementation 'junit:junit:4.12'
//noinspection GradleCompatible
// androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.gms:play-services-ads:20.6.0'
// Room
implementation 'androidx.room:room-runtime:2.2.2'
kapt 'androidx.room:room-compiler:2.2.2'
kapt "com.android.databinding:compiler:3.1.4"
// Test helpers for Room
testImplementation 'androidx.room:room-testing:2.2.2'
implementation 'com.kovacorp.vocalizesdk:VocalizeSDK:0.0.7'
implementation "com.google.assistant.appactions:suggestions:1.0.0"
}
The distribution URL which I used in gradle-wrapper.properties is as follows:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
I have checked all the res files. But there is no error in any files. Please suggest any approach to solve this. Thanks in advance.
I just add Realm Database in my Project. But now my Gradle giving me error "Read Time out"
Below I'm showing full error image.
I'm Following Realm Documentation as they mention but still getting Error.
Please help me I'm trying to resolve this issue but didn't get any single issue related to this
build.gradle(Project)
buildscript {
repositories {
maven {
url 'https://jitpack.io'
}
google()
jcenter()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
classpath "io.realm:realm-gradle-plugin:10.9.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(Module)
plugins {
id 'com.android.application'
id 'realm-android'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.app.model_farming"
minSdk 21
targetSdk 31
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
}
buildFeatures {
viewBinding true
}
}
realm {
syncEnabled = true
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.navigation:navigation-fragment:2.3.5'
implementation 'androidx.navigation:navigation-ui:2.3.5'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.google.code.gson:gson:2.8.8'
implementation 'com.squareup.okhttp3:logging-interceptor:4.3.1'
// Meow Bottom Navigation Bar -- Not to Update
implementation 'com.etebarian:meow-bottom-navigation:1.2.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.32"
//OTP PinView
//Loading Bar
implementation 'com.github.ybq:Android-SpinKit:1.4.0'
//Shimmer
implementation 'com.facebook.shimmer:shimmer:0.5.0'
// Lottie dependency
def lottieVersion = "3.4.0"
//noinspection GradleDependency
implementation "com.airbnb.android:lottie:$lottieVersion"
implementation 'com.evrencoskun.library:tableview:0.8.9.4'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
}
on build.gradle(Module) , add (id 'kotlin-kapt') before (id 'realm-android')
plugins {
id 'com.android.application'
id 'kotlin-kapt'
id 'realm-android'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.app.model_farming"
minSdk 21
targetSdk 31
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
}
buildFeatures {
viewBinding true
}
}
realm {
syncEnabled = true
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.navigation:navigation-fragment:2.3.5'
implementation 'androidx.navigation:navigation-ui:2.3.5'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.google.code.gson:gson:2.8.8'
implementation 'com.squareup.okhttp3:logging-interceptor:4.3.1'
// Meow Bottom Navigation Bar -- Not to Update
implementation 'com.etebarian:meow-bottom-navigation:1.2.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.32"
//OTP PinView
//Loading Bar
implementation 'com.github.ybq:Android-SpinKit:1.4.0'
//Shimmer
implementation 'com.facebook.shimmer:shimmer:0.5.0'
// Lottie dependency
def lottieVersion = "3.4.0"
//noinspection GradleDependency
implementation "com.airbnb.android:lottie:$lottieVersion"
implementation 'com.evrencoskun.library:tableview:0.8.9.4'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
}
while the project is syncing i get the error below at the line 18 resVlaue("") :
A problem occurred evaluating project ':app'.
Parameter specified as non-null is null: method com.android.build.gradle.internal.dsl.BaseFlavor.resValue, parameter value
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs"
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def fbApiScheme = properties.getProperty('fbApiScheme')
def fbApiKey = properties.getProperty('fbApiKey')
android {
lintOptions {
baseline file("lint-baseline.xml")
}
compileSdkVersion rootProject.ext.compileSdk
defaultConfig {
resValue("string", "fbApiKey", fbApiKey)
resValue("string", "fbApiScheme", fbApiScheme)
vectorDrawables.useSupportLibrary = true
applicationId "org.aossie.agoraandroid"
minSdkVersion rootProject.ext.minSdk
targetSdkVersion targetSdk
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
}
}
buildFeatures {
dataBinding = true
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "androidx.appcompat:appcompat:$appCompatVersion"
implementation "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion"
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation "junit:junit:$junitVersion"
androidTestImplementation "androidx.test:runner:$testRunnerVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoCoreVersion"
// Lifecycle components
implementation "androidx.lifecycle:lifecycle-extensions:$archLifecycleVersion"
kapt "androidx.lifecycle:lifecycle-compiler:2.3.1"
//Design Support Library
implementation "com.google.android.material:material:$materialDesignVersion"
//Library for CardView
implementation "androidx.cardview:cardview:$cardViewVersion"
//Retrofit
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
implementation "com.squareup.retrofit2:converter-scalars:$retrofitConverterScalarsVersion"
//GSON and GSON converter
implementation "com.squareup.retrofit2:converter-gson:$retrofitConverterGsonVersion"
implementation "com.google.code.gson:gson:$gsonVersion"
//Navigation Architecture Dependencies
implementation "androidx.navigation:navigation-fragment-ktx:$navFragmentVersion"
implementation "androidx.navigation:navigation-ui-ktx:$navUiVersion"
//Shimmer
implementation "com.facebook.shimmer:shimmer:$facebookShimmerVersion"
//Facebook Login
implementation "com.facebook.android:facebook-login:$facebookLoginVersion"
implementation 'com.facebook.android:facebook-android-sdk:9.1.0'
//Pie Chart
implementation "com.github.PhilJay:MPAndroidChart:v3.1.0"
//MockWebServer and Roboelectric
testImplementation "org.robolectric:robolectric:$robolectricVersion"
testImplementation "com.squareup.okhttp3:mockwebserver:$mockWebServerVersion"
// Mockito
testImplementation "org.mockito:mockito-core:$mockitoCoreVersion"
testImplementation 'org.json:json:20210307'
//kotlin deps
implementation "androidx.core:core-ktx:1.3.2"
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1' //TODO
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.31'
//dagger
implementation "com.google.dagger:dagger:$daggerVersion"
kapt "com.google.dagger:dagger-compiler:$daggerVersion"
//Shared Prefs
implementation "androidx.preference:preference-ktx:$prefsVersion"
// room
implementation "androidx.room:room-runtime:$roomVersion"
kapt "androidx.room:room-compiler:$roomVersion"
implementation "androidx.room:room-ktx:$roomVersion"
// coroutine
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutineVersion"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3-native-mt'
//horizontal calendar
implementation "devs.mulham.horizontalcalendar:horizontalcalendar:$calendarVersion"
//day view lib
implementation "com.linkedin.android.tachyon:tachyon:$tachyonVersion"
//picasso
implementation "com.squareup.picasso:picasso:$picassoVersion"
//timber
implementation "com.jakewharton.timber:timber:$timberVersion"
//httpLoggingInterceptor
implementation "com.squareup.okhttp3:logging-interceptor:$httpLoggingInterceptor"
//chucker
debugImplementation "com.github.chuckerteam.chucker:library:$chuckerVersion"
releaseImplementation "com.github.chuckerteam.chucker:library-no-op:$chuckerVersion"
//leakcanary
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanaryVersion"
}
repositories {
mavenCentral()
}
My project has two modules i.e. app and moduleX.
app project is mostly built on Java and moduleX is completly in Kotlin.
While creating "debug" build, it's running fine but when I try to create release build i.e. devRelease, it give following error-
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithDexMergerForDevRelease'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: android.support.compat.R$attr
Here is the app level build.gradle-
apply plugin: 'com.android.application'
apply plugin: 'com.facebook.testing.screenshot'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
applicationId "com.appname"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
testInstrumentationRunner rootProject.ext.testInstrumentationRunner
}
flavorDimensions "environment"
productFlavors {
dev {
dimension "environment"
versionNameSuffix "-dev"
applicationIdSuffix ".dev"
}
qa {
dimension "environment"
versionNameSuffix "-test"
applicationIdSuffix ".test"
}
staging {
dimension "environment"
versionNameSuffix "-staging"
applicationIdSuffix ".staging"
}
prod {
dimension "environment"
}
}
signingConfigs {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
release {
storeFile file("keystore/appname_keystore.jks")
storePassword properties.getProperty('storePassword')
keyAlias properties.getProperty('keyAlias')
keyPassword properties.getProperty('keyPassword')
}
}
buildTypes {
debug {
shrinkResources false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
shrinkResources false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
bundle {
language {
enableSplit = false
}
}
configurations.all {
resolutionStrategy {
// force certain versions of dependencies (including transitive)
force 'com.squareup.okhttp3:okhttp:' + okHttpLibVersion
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//Unit testing
testImplementation rootProject.ext.junit
androidTestImplementation rootProject.ext.androidTestRunner
androidTestImplementation rootProject.ext.espresso
testImplementation rootProject.ext.mockito
testImplementation rootProject.ext.facebookScreenshotTestCommon
implementation rootProject.ext.facebookScreenshotTestLitho
androidTestImplementation rootProject.ext.supportTestRules
//Support Library & UI
implementation rootProject.ext.constraintLayout
implementation rootProject.ext.supportCompatV7
implementation rootProject.ext.supportDesign
implementation rootProject.ext.supportCardView
implementation rootProject.ext.supportCustomTabs
implementation rootProject.ext.glide
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
// Dagger dependency for DI
implementation 'com.google.dagger:dagger:2.16'
annotationProcessor "com.google.dagger:dagger-compiler:2.16"
compileOnly 'javax.annotation:jsr250-api:1.0'
implementation 'javax.inject:javax.inject:1'
// RxJava lib
implementation rootProject.ext.rxAndroid
implementation rootProject.ext.rxJava
implementation rootProject.ext.rxJavaRetrofitAdapter
//Retrofit
implementation(rootProject.ext.retrofit) {
exclude module: 'okhttp'
}
implementation rootProject.ext.okHttp
implementation rootProject.ext.okHttpLoggingInterceptor
implementation rootProject.ext.retrofitGsonConverter
implementation rootProject.ext.retrofitScalarsConverter
//Memory leaks
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.3'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'
debugImplementation 'com.squareup.leakcanary:leakcanary-support-fragment:1.6.3'
//Others
implementation rootProject.ext.parceler
annotationProcessor rootProject.ext.parcelerAnnotationProcessor
implementation rootProject.ext.lombok
annotationProcessor rootProject.ext.lombokAnnotationProcessor
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
// Fingerprint Auth
implementation 'com.multidots:fingerprint-auth:1.0.1'
//Module Projects
api project(':energyswitchcui')
}
screenshots {
multipleDevices true
}
and here is the build.gradle file of moduleX-
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
// need separate runner for facebook screenshot test in module
testInstrumentationRunner 'com.appname.SnapshotTestRunner'
}
flavorDimensions "environment"
productFlavors {
dev {
dimension "environment"
}
qa {
dimension "environment"
}
staging {
dimension "environment"
}
prod {
dimension "environment"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
test.java.srcDirs += 'src/test/kotlin'
androidTest.java.srcDirs += 'src/androidTest/kotlin'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//Unit testing
testImplementation rootProject.ext.junit
androidTestImplementation rootProject.ext.androidTestRunner
androidTestImplementation rootProject.ext.espresso
testImplementation rootProject.ext.mockito
testImplementation rootProject.ext.facebookScreenshotTestCommon
implementation rootProject.ext.facebookScreenshotTestLitho
androidTestImplementation rootProject.ext.supportTestRules
//Support Library & UI
implementation rootProject.ext.constraintLayout
implementation rootProject.ext.supportCompatV7
implementation rootProject.ext.supportDesign
implementation rootProject.ext.supportCardView
implementation rootProject.ext.supportCustomTabs
implementation rootProject.ext.glide
implementation 'com.intuit.sdp:sdp-android:1.0.6'
// RxJava lib
implementation rootProject.ext.rxAndroid
implementation rootProject.ext.rxJava
implementation rootProject.ext.rxJavaRetrofitAdapter
//Retrofit
implementation(rootProject.ext.retrofit) {
exclude module: 'okhttp'
}
implementation rootProject.ext.okHttp
implementation rootProject.ext.okHttpLoggingInterceptor
implementation rootProject.ext.retrofitGsonConverter
implementation rootProject.ext.retrofitScalarsConverter
//Others
implementation rootProject.ext.parceler
kapt rootProject.ext.parcelerAnnotationProcessor
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
}
repositories {
mavenCentral()
}
// need for facebook screenshot test in module
apply plugin: 'com.facebook.testing.screenshot'
screenshots {
multipleDevices true
}
This is the project level build.gradle file-
apply from: 'dependencies.gradle'
buildscript {
ext.kotlinVersion = '1.3.30'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.facebook.testing.screenshot:plugin:0.8.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
This is dependencies.gradle-
ext {
//Android
minSdkVersion = 24
targetSdkVersion = 28
compileSdkVersion = targetSdkVersion
testInstrumentationRunner = "com.appname.runner.SnapshotTestRunner"
androidSupportLibVersion = "28.0.0"
okHttpLibVersion = "3.14.0"
//Unit testing
junit = "junit:junit:4.12"
androidTestRunner = "com.android.support.test:runner:1.0.2"
espresso = "com.android.support.test.espresso:espresso-core:3.0.2"
mockito = "org.mockito:mockito-all:1.10.19"
facebookScreenshotTestCommon = "com.facebook.testing.screenshot:layout-hierarchy-common:0.8.0"
facebookScreenshotTestLitho = "com.facebook.testing.screenshot:layout-hierarchy-litho:0.8.0"
supportTestRules = "com.android.support.test:rules:1.0.2"
//Support Library & UI
constraintLayout = "com.android.support.constraint:constraint-layout:1.1.3"
supportCompatV7 = "com.android.support:appcompat-v7:$androidSupportLibVersion"
supportDesign = "com.android.support:design:$androidSupportLibVersion"
supportCardView = "com.android.support:cardview-v7:$androidSupportLibVersion"
supportCustomTabs = "com.android.support:customtabs:$androidSupportLibVersion"
glide = "com.github.bumptech.glide:glide:3.7.0"
// RxJava lib
rxAndroid = "io.reactivex.rxjava2:rxandroid:2.0.1"
rxJava = "io.reactivex.rxjava2:rxjava:2.1.8"
rxJavaRetrofitAdapter = "com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0"
//Retrofit
retrofit = "com.squareup.retrofit2:retrofit:2.4.0"
okHttp = "com.squareup.okhttp3:okhttp:$okHttpLibVersion"
okHttpLoggingInterceptor = "com.squareup.okhttp3:logging-interceptor:$okHttpLibVersion"
retrofitGsonConverter = "com.squareup.retrofit2:converter-gson:2.3.0"
retrofitScalarsConverter = "com.squareup.retrofit2:converter-scalars:2.3.0"
//Others
parceler = "org.parceler:parceler-api:1.1.6"
parcelerAnnotationProcessor = "org.parceler:parceler:1.1.6"
lombok = "org.projectlombok:lombok:1.16.16"
lombokAnnotationProcessor = "org.projectlombok:lombok:1.16.16"
}
I have already tried many answers i.e.
Error : Program type already present: android.support.design.widget.CoordinatorLayout$Behavior
but nothing is working here.
Hi i have come up with the solution and run successful below gradles with just little version changes:
Main Project Level Gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.30'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.facebook.testing.screenshot:plugin:0.8.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ext {
//Android
minSdkVersion = 24
targetSdkVersion = 28
compileSdkVersion = targetSdkVersion
testInstrumentationRunner = "com.appname.runner.SnapshotTestRunner"
androidSupportLibVersion = "28.0.0"
androidCompatVersion = "1.0.0-beta01"
androidCardViewVersion = "1.0.0"
constraintlayoutVersion = "1.1.3"
okHttpLibVersion = "3.14.0"
//Unit testing
junit = "junit:junit:4.12"
androidTestRunner = "androidx.test:runner:1.1.0-alpha4"
espresso = "androidx.test.espresso:espresso-core:3.1.0-alpha4"
supportTestRules = "com.android.support.test:rules:1.0.2"
//Support Library & UI
constraintLayout = "androidx.constraintlayout:constraintlayout:$constraintlayoutVersion"
supportCompatV7 = "androidx.appcompat:appcompat:$androidCompatVersion"
supportDesign = "com.android.support:design:$androidSupportLibVersion"
supportCardView = "androidx.cardview:cardview:$androidCardViewVersion"
supportCustomTabs = "com.android.support:customtabs:$androidSupportLibVersion"
glide = "com.github.bumptech.glide:glide:3.7.0"
mockito = "org.mockito:mockito-all:1.10.19"
facebookScreenshotTestCommon = "com.facebook.testing.screenshot:layout-hierarchy-common:0.8.0"
facebookScreenshotTestLitho = "com.facebook.testing.screenshot:layout-hierarchy-litho:0.8.0"
// RxJava lib
rxAndroid = "io.reactivex.rxjava2:rxandroid:2.0.1"
rxJava = "io.reactivex.rxjava2:rxjava:2.1.8"
rxJavaRetrofitAdapter = "com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0"
//Retrofit
retrofit = "com.squareup.retrofit2:retrofit:2.4.0"
okHttp = "com.squareup.okhttp3:okhttp:$okHttpLibVersion"
okHttpLoggingInterceptor = "com.squareup.okhttp3:logging-interceptor:$okHttpLibVersion"
retrofitGsonConverter = "com.squareup.retrofit2:converter-gson:2.3.0"
retrofitScalarsConverter = "com.squareup.retrofit2:converter-scalars:2.3.0"
//Others
parceler = "org.parceler:parceler-api:1.1.9"
parcelerAnnotationProcessor = "org.parceler:parceler:1.1.9"
lombok = "org.projectlombok:lombok:1.16.16"
lombokAnnotationProcessor = "org.projectlombok:lombok:1.16.16"
}
App Level gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.example.gradletest"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation rootProject.ext.junit
androidTestImplementation rootProject.ext.androidTestRunner
androidTestImplementation rootProject.ext.espresso
androidTestImplementation rootProject.ext.supportTestRules
testImplementation rootProject.ext.mockito
testImplementation rootProject.ext.facebookScreenshotTestCommon
implementation rootProject.ext.facebookScreenshotTestLitho
implementation rootProject.ext.constraintLayout
implementation rootProject.ext.supportCompatV7
implementation rootProject.ext.supportDesign
implementation rootProject.ext.supportCardView
implementation rootProject.ext.supportCustomTabs
implementation rootProject.ext.glide
// RxJava lib
implementation rootProject.ext.rxAndroid
implementation rootProject.ext.rxJava
implementation rootProject.ext.rxJavaRetrofitAdapter
//Retrofit
implementation(rootProject.ext.retrofit) {
exclude module: 'okhttp'
}
implementation rootProject.ext.okHttp
implementation rootProject.ext.okHttpLoggingInterceptor
implementation rootProject.ext.retrofitGsonConverter
implementation rootProject.ext.retrofitScalarsConverter
implementation rootProject.ext.parceler
// annotationProcessor rootProject.ext.parcelerAnnotationProcessor
implementation rootProject.ext.lombok
annotationProcessor rootProject.ext.lombokAnnotationProcessor
//Memory leaks
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.3'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'
debugImplementation 'com.squareup.leakcanary:leakcanary-support-fragment:1.6.3'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.multidots:fingerprint-auth:1.0.1'
implementation project(':energyswitchcui')
}
Module("energyswitchcui") gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//Unit testing
testImplementation rootProject.ext.junit
androidTestImplementation rootProject.ext.androidTestRunner
androidTestImplementation rootProject.ext.espresso
testImplementation rootProject.ext.mockito
testImplementation rootProject.ext.facebookScreenshotTestCommon
implementation rootProject.ext.facebookScreenshotTestLitho
androidTestImplementation rootProject.ext.supportTestRules
//Support Library & UI
implementation rootProject.ext.constraintLayout
implementation rootProject.ext.supportCompatV7
implementation rootProject.ext.supportDesign
implementation rootProject.ext.supportCardView
implementation rootProject.ext.supportCustomTabs
implementation rootProject.ext.glide
implementation 'com.intuit.sdp:sdp-android:1.0.6'
// RxJava lib
implementation rootProject.ext.rxAndroid
implementation rootProject.ext.rxJava
implementation rootProject.ext.rxJavaRetrofitAdapter
//Retrofit
implementation(rootProject.ext.retrofit) {
exclude module: 'okhttp'
}
implementation rootProject.ext.okHttp
implementation rootProject.ext.okHttpLoggingInterceptor
implementation rootProject.ext.retrofitGsonConverter
implementation rootProject.ext.retrofitScalarsConverter
//Others
implementation rootProject.ext.parceler
// kapt rootProject.ext.parcelerAnnotationProcessor
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
mavenCentral()
}
// need for facebook screenshot test in module
apply plugin: 'com.facebook.testing.screenshot'
screenshots {
multipleDevices true
}
Below are the errors that were encountered during gradle and what i have done to solve it:
1) Error: Invoke-customs are only supported starting with Android O (--min-api 26)
Solution: put below lines under android section of app level gradle
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
2) Error: The given artifact contains a string literal with a package reference 'android.support.v4.widget' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.
Solution: Removed "annotationProcessor rootProject.ext.parcelerAnnotationProcessor" from app level gradle and updated this library in main level gradle under "ext" section from 1.1.6 to 1.1.9 'parcelerAnnotationProcessor = "org.parceler:parceler:1.1.9"'
but it does not worked
So i removed that library and successfully build gradle and also can run the project. Here is the dropbox link you can find project on :https://www.dropbox.com/s/ki8gpfdaxh0dzo3/GradleTest.zip?dl=0
3) Above solution will work only in debug mode but in release build we have to also remove this two libraries to build successfully in release build:
facebookScreenshotTestCommon = "com.facebook.testing.screenshot:layout-hierarchy-common:0.9.0"
facebookScreenshotTestLitho = "com.facebook.testing.screenshot:layout-hierarchy-litho:0.9.0"