Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android gradle build with library, cannot find symbol

I am trying to build an Android Application that uses a Android Library that I have also created. Project structure is as follows:

/mainProject
    |- /myLibrary
        |- build.gradle
        |- (Java Sources and files)
    |- /app
        |- build.gradle
        |- (Java Sources and files)
    |- settings.gradle
    |- build.gradle

The mainProject/settings.gradle contains:

include ':app', ':myLibrary'

The mainProject/build.gradle contains:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

The mainProject/myLibrary/build.gradle looks like this:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

apply plugin: 'com.android.library'

android {
    compileSdkVersion 21
    buildToolsVersion "23.0.1"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        debug{
            buildConfigField "String", "LIBRARY_ENDPOINT", "\"https://dev-library.company.com/\""
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField "String", "LIBRARY_ENDPOINT", "\"https://library.company.com/\""
        }
    }
}

repositories {
    jcenter()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.+'
    compile 'com.github.satyan:sugar:1.3'
    testCompile 'junit:junit:4.12'
    compile 'commons-io:commons-io:2.4'
    androidTestCompile 'junit:junit:4.12'
}

The mainProject/app/build.gradle file contains:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.company.app"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        debug {
            applicationIdSuffix ".debug"
            buildConfigField "String", "APP_ENDPOINT", "\"https://dev-app.company.com/\""
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            buildConfigField "String", "APP_ENDPOINT", "\"https://app.company.com/\""
        }
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:21.+'
    compile 'com.google.android.gms:play-services-location:8.1.0'
    compile 'commons-io:commons-io:2.4'
    compile 'com.joanzapata.pdfview:android-pdfview:1.0.4@aar'
    compile 'com.github.clans:fab:1.6.1'
    compile 'joda-time:joda-time:2.8.2'
    compile 'com.android.support:recyclerview-v7:+'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile project(':myLibrary')
}

I originally was getting errors in the IDE, but adding the final compile project line cleared those up, so the IDE doesn't show any errors at all. However, when I run the gradle build I am seeing:

:app:compileDebugJavaWithJavac
/AndroidStudioProjects/mainProject/app/src/main/java/com/company/app/MainActivity.java:17: error: cannot find symbol
import com.company.mylibrary.LibraryClass;
                                    ^
  symbol:   class LibraryClass
  location: package com.company.mylibrary
/AndroidStudioProjects/mainProject/app/src/main/java/com/company/app/MainActivity.java:29: error: cannot find symbol
        LibraryClass.setup("562e7d58628ee16894db98df", getApplicationContext());
        ^
  symbol:   variable LibraryClass
  location: class MainActivity
2 errors

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 8.143 secs

I am confused because the IDE doesn't show any errors, and I believe that I have told gradle that the app project does need the myLibrary project at compile time. None of the answers I have found on here seem to have the same issue.

Does anyone see what I am doing wrong?

like image 211
Innova Avatar asked Mar 15 '23 08:03

Innova


1 Answers

Finally figured out the issue. My library was using proguard, and for some reason that was messing things up. I removed the minify and proguard lines from the build.gradle in the library project and it worked.

like image 193
Innova Avatar answered Mar 23 '23 16:03

Innova