Gradle android cannot find symbol Context - java

I have a java + kotlin android project that builds and runs fine in Android Studio. I am now setting up CI and need to run Gradle from the terminal.
But when I run ./gradlew :app:lint I get a lot of errors like this:
symbol: class Context
location: class ConnectivityMonitor
e: /*******/LocalAppHistory.java:20: error: cannot find symbol
public boolean hasSeenOnboarding(Context context) {
^
I get the same type of error for Context, CognitoUserSession, Typeface, CognitoCachingCredentialsProvider... and many more.
It only applies to the app project and none of the other modules.
The app gradle.build file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "****"
minSdkVersion 21
targetSdkVersion 27
versionCode 48
versionName "1.3.0-dev"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
renderscriptTargetApi 18
renderscriptSupportModeEnabled true
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
}
}
testOptions {
unitTests.returnDefaultValues = true
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':corentiumio')
implementation project(':uicomponents')
implementation project(':core')
implementation project(':localrepo')
implementation project(':cloudio')
implementation('com.crashlytics.sdk.android:crashlytics:2.6.6#aar') {
transitive = true
}
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:animated-vector-drawable:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.amazonaws:aws-android-sdk-core:2.4.2'
implementation 'com.amazonaws:aws-android-sdk-ddb:2.2.22'
implementation 'com.amazonaws:aws-android-sdk-ddb-mapper:2.2.22'
implementation 'com.amazonaws:aws-android-sdk-cognito:2.4.2'
implementation 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.4.2'
implementation 'com.google.android.gms:play-services-places:15.0.0'
implementation 'com.google.android.gms:play-services-maps:15.0.0'
implementation 'com.google.android.gms:play-services-location:15.0.0'
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
testImplementation 'commons-logging:commons-logging:1.2'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.13.0'
testImplementation 'org.robolectric:robolectric:3.5.1'
androidTestImplementation 'com.google.code.findbugs:jsr305:3.0.2'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestImplementation('com.android.support.test:runner:0.5') {
exclude group: 'com.android.support'
}
androidTestImplementation('com.android.support.test:rules:0.5') {
exclude group: 'com.android.support'
}
androidTestImplementation('com.android.support.test.espresso:espresso-intents:2.2.2') {
exclude group: 'com.android.support'
}
}

I may be wrong, once I got this error while switching git branch from Kotlin Compiler that can't find symbols.
I did clear cache then it worked,
rm -rf $HOME/.gradle/caches/
Seems while switching branch previous branch files cached created this issue.
Give a try if you want.

Related

How to fix gradle when this error appear?

I started a new project and put fire-base cloud:
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "android.example.com.squawker"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
// RecyclerView
implementation 'com.android.support:recyclerview-v7:28.0.0'
// Schematic dependencies for ContentProvider
apt 'net.simonvt.schematic:schematic-compiler:0.6.3'
implementation 'net.simonvt.schematic:schematic:0.6.3'
// Preferences Dependencies
implementation 'com.android.support:preference-v7:28.0.0'
// Firebase dependency
implementation 'com.google.firebase:firebase-messaging:17.3.4'
}
// Apply the Google Services plugin. Make sure to add the google-services.json file in the app
// folder. You download it from the Firebase console
apply plugin: 'com.google.gms.google-services'
and this error apeared:
WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variant.getJavaCompile(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace.
Affected Modules: app
This probably because of apt plugin which is already obsolete. So, you need to remove the following:
apply plugin: 'android-apt'
then change the following:
apt 'net.simonvt.schematic:schematic-compiler:0.6.3'
with:
annotationProcessor 'net.simonvt.schematic:schematic-compiler:0.6.3'
Similar to API 'variant.getExternalNativeBuildTasks()' is obsolete and has been replaced with 'variant.getExternalNativeBuildProviders() Happy Coding!

Failed to resolve: com.android.support:design:28.0

When I hover over my 'com.android.support:appcompat-v7:28.0.0' in my build.gradle , it says that the support libaries must use the exact same version specifications. I got this error out of no where where after pulling in some files from my repo on github. I first referred to All com.android.support libraries must use the exact same version specification where many of the solutions were posted but after trying many of them, I could not still resolve my issue. I will list the steps below that I took to try to resolve the issue. Any help would be great on this. I will also post my build.gradle below.
steps taken to resolve issue
Sync project with Gradle File
Invalidate caches and Restart
Created a new project and basically copied everything from the one with issues into it
I also added the following code into my build.gradle and it did not work either.
configurations.all {
resolutionStrategy.eachDependency {
DependencyResolveDetails details ->
def requested = details.requested
if (requested.group ==
'com.android.support') {
if
(!requested.name.startsWith("multidex")) {
details.useVersion '28.0.0'
}
}
}
}
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "losdos.help4hire"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0 '
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android.gms:play-services-auth:12.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-database:16.0.3'
implementation 'com.google.firebase:firebase-firestore:17.1.2'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.firebase:firebase-client-android:2.5.2+'
implementation 'com.google.firebase:firebase-auth:16.0.5'
}
apply plugin: 'com.google.gms.google-services'
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '28.0.0 '
}
}
}
}

Error:Execution failed for task ':app:javaPreCompileDebug'

android
{
compileSdkVersion 27
defaultConfig
{
applicationId "downloader.video.full.videodownloader"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.1"
useLibrary 'org.apache.http.legacy'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes
{
release
{
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-
rules.pro'
}
}
}
dependencies
{
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.2'
implementation 'com.io.tools.android.ramiloif.folderchooser:folderchooser-
dialog:1.0.6'
implementation 'com.google.android.gms:play-services-plus:10.0.1'
implementation 'com.google.android.gms:play-services-ads:10.0.1'
implementation 'com.android.support:design:27.1.1'
implementation files('libs/json-20140107.jar')
implementation 'com.squareup.okio:okio:1.14.1'
implementation 'com.squareup.picasso:picasso:2.71828'
compile 'com.google.android.gms:play-services-analytics:10.0.1'
}
I get this error when I build my code:
Error:Execution failed for task ':app:javaPreCompileDebug'.
> Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found to contain annotation processor. Please add them to the annotationProcessor configuration.
- lombok-1.16.14.jar (org.projectlombok:lombok:1.16.14)
Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior. Note that this option is deprecated and will be removed in the future.
See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.
This is my project gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
It tells you what to do...
> Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found to contain annotation processor.
> Please add them to the annotationProcessor configuration.
- lombok-1.16.14.jar (org.projectlombok:lombok:1.16.14)
Like so
dependencies {
// Other dependencies
compileOnly "org.projectlombok:lombok:1.18.4"
annotationProcessor 'org.projectlombok:lombok:1.18.4'
}
[See Lombok documentation](https://projectlombok.org/setup/android)
Also, I suggest you delete `libs/json-20140107.jar` and replace it with
compile 'org.json:json:20140107'
Although, Android already has a JSON parser, so not clear why you need this at all
Just Add Following Lines into your Module:app gradle file
dependencies {
compileOnly "org.projectlombok:lombok:1.18.4"
annotationProcessor 'org.projectlombok:lombok:1.18.4'
}

Facebook sdk conflict, compatibility error ? - Duplicate value for resource 'attr/font' with config "

I am trying to use Facebook login API, but when I write the "implementation" in gradle file, I get an error:
Error:(252, 5) error: duplicate value for resource 'attr/font' with config ''.
Error:(252, 5) error: resource previously defined here.
When I click on "Jump to source", Android Studio brings me in a file "values.xml", a non-writable file, that looks like this:
// More stuff above, the following line is where the error brings me
<dimen name="abc_action_bar_content_inset_material">16dp</dimen>
<dimen name="abc_action_bar_content_inset_with_nav">72dp</dimen>
<dimen name="abc_action_bar_default_height_material">56dp</dimen>
<dimen name="abc_action_bar_default_padding_end_material">0dp</dimen>
<dimen name="abc_action_bar_default_padding_start_material">0dp</dimen>
// More stuff
Here is my 'app' build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 27
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.discodery.android.discoderyapp"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
buildTypes.each {
it.buildConfigField 'Integer', 'RESTAURANT_ID', '2'
}
}
/*
productFlavors {
dev {
}
prod {
}
}*/
dataBinding {
enabled = true
}
}
kapt {
generateStubs = true
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile 'com.mikhaellopez:circularimageview:3.0.2'
compile 'de.hdodenhof:circleimageview:2.2.0'
//Permissions
compile 'com.beust:klaxon:2.0.11'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.1.6'
compile 'com.hwangjr.rxbus:rxbus:1.0.5'
compile 'org.parceler:parceler-api:1.1.6'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.4.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.google.dagger:dagger:2.7'
compile 'com.facebook.fresco:fresco:1.0.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.slider:library:1.1.5#aar'
compile 'com.karumi:dexter:2.3.1'
testCompile 'junit:junit:4.12'
kapt 'com.android.databinding:compiler:2.3.0'
kapt 'org.parceler:parceler:1.1.6'
kapt 'com.google.dagger:dagger-compiler:2.7'
compile 'com.google.android.gms:play-services-vision:11.6.0'
// Facebook SDK Core only (Analytics)
implementation 'com.facebook.android:facebook-core:4.+'
// Facebook Login only
implementation 'com.facebook.android:facebook-login:4.+'
// Facebook Share only
implementation 'com.facebook.android:facebook-share:4.+'
// Facebook Places only
implementation 'com.facebook.android:facebook-places:4.+'
// Facbeook Messenger only
implementation 'com.facebook.android:facebook-messenger:4.+'
// Facebook App Links only
implementation 'com.facebook.android:facebook-applinks:4.+'
// Facebook Android SDK (everything)
implementation 'com.facebook.android:facebook-android-sdk:4.+'
// Audience Network SDK. Only versions 4.6.0 and above are available
implementation 'com.facebook.android:audience-network-sdk:4.+'
// Account Kit
implementation 'com.facebook.android:account-kit-sdk:4.+'
}
repositories {
jcenter()
mavenCentral()
}
apply plugin: 'kotlin-android-extensions'
Does someone have an idea about which "implementation" or "compile" line it could be from?
Without the Facebook SDK implementation lines, the project does compile and works properly.
As the logs tell me "duplicate value", I think that Facebook SKDs create some values like strings, that have exactly the same id or name that an other SDK.
Does anyone have a solution for this?
EDIT
The question concern the compatibility errors with Facebook SDK.
Is there a way to see if a dependency is or is not compatible with another one?

How to solve a Duplicate zip entry

I have this problem: When I run my project on Android Studio it works fine, but when I try to Build the APK (on BUILD > BUILD Apk(s)) it shows me the next error:
Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
java.io.IOException: Can't write [/Users/sergio/Documents/ink/touch_android/app/build/intermediates/multi-dex/debug/componentClasses.jar] (Can't read [/Users/sergio/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-databind/2.3.3/63b77400b5f1cf83a81823562c48d3120ef5518e/jackson-databind-2.3.3.jar(;;;;;;**.class)] (Duplicate zip entry [jackson-databind-2.3.3.jar:com/fasterxml/jackson/databind/JsonDeserializer$None.class]))
as far as I know this is caused by a duplicated class called JsonDeserializer, that I found on my project
but I can't find a way to 'unlink' this files from each jar listed. This is my gradle file.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "---"
minSdkVersion 19
targetSdkVersion 23
versionCode -
versionName "-"
renderscriptTargetApi 22
renderscriptSupportModeEnabled true
multiDexEnabled true
ndk {
abiFilters "x86", "armeabi-v7a", "armeabi"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { resources.srcDirs = ['src/main/resources', 'src/main/java/includes'] } }
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
}
}
dependencies
{
//compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
implementation files('libs/gson-2.5.jar')
implementation files('libs/guava-18.0.jar')
implementation files('libs/snmp6_1.jar')
implementation 'com.crittercism:crittercism-android-agent:5.6.4'
implementation files('libs/jackson-annotations-2.2.3.jar')
implementation files('libs/jackson-databind-2.2.3.jar')
implementation files('libs/httpmime-4.3.2.jar')
implementation files('libs/httpcore-4.3.1.jar')
implementation files('libs/commons-lang3-3.4.jar')
implementation files('libs/commons-validator-1.4.0.jar')
implementation files('libs/jackson-core-2.2.3.jar')
implementation files('libs/commons-net-3.1.jar')
implementation files('libs/ZSDK_ANDROID_API.jar')
implementation files('libs/opencsv-2.2.jar')
implementation files('libs/commons-io-2.2.jar')
implementation files('libs/mrzjniInterfaceJar.jar')
implementation 'com.kyleduo.switchbutton:library:1.4.1'
implementation 'com.github.nkzawa:socket.io-client:0.3.0'
implementation 'fr.tvbarthel.blurdialogfragment:lib:2.2.0'
implementation 'com.android.support:multidex:1.0.1'
implementation('de.keyboardsurfer.android.widget:crouton:1.8.5#aar')
implementation 'com.android.support:appcompat-v7:23.4.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:23.4.0'
implementation files('libs/cw-deviceapi20171026.jar')
implementation 'org.jmrtd:jmrtd:0.5.5'
implementation 'net.sf.scuba:scuba-sc-android:0.0.9'
implementation 'com.madgag.spongycastle:prov:1.54.0.0'
implementation 'edu.ucar:jj2000:5.2'
implementation 'com.github.mhshams:jnbis:1.1.0'
implementation files('libs/BrotherPrintLibrary.jar')
implementation files('libs/MobilePrintLib.jar')
}
try removing this implementation
implementation files('libs/jackson-core-2.2.3.jar')
and do
Build > Clean Project
In the module where you are adding jackson dependency exclude that class which is already in the other lib. Otherwise, exclude it from the other lib and leave it on the jackson.

Categories