Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android studio - App with library project fails to build

I'm having massive trouble trying to get my app project to build. I have the main app module and a library project module as shown below:

Project Structure

This is the gradle.build for each of the modules:

Main App:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'
repositories {
    mavenCentral()
}
android {
    compileSdkVersion 19
    buildToolsVersion '19.0.0'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
    }
    buildTypes {
        release {
            runProguard true
            proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
        }
    }
    productFlavors {
        defaultFlavor {
            proguardFile 'proguard-rules.txt'
        }
    }
}
dependencies {
    compile 'com.android.support:support-v13:19.0.+'
    compile 'com.google.android.gms:play-services:4.0.+'
    compile project(':libraries:datetimepicker')
}

And this one is for the library Project:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android-library'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
    }
    release {
        runProguard true
        proguardFile 'proguard-rules.txt'
        proguardFile getDefaultProguardFile('proguard-android-ptimize.txt')
    }
}

dependencies {
    compile 'com.android.support:support-v4:19.0.+'
}

Finally, This is the project settings.gradle file.

include ':App', ':libraries:datetimepicker'

I am able to successfully import packages from the library to my App code and use them, however when I try to compile I get the following:

Gradle: Execution failed for task ':App:compileDefaultFlavorDebug'.
> Compilation failed; see the compiler error output for details.

E:\blah\blah\MyClass.java
Gradle: error: cannot find symbol class DatePickerDialog
Gradle: error: package DatePickerDialog does not exist
Gradle: error: cannot find symbol class DatePickerDialog
Gradle: error: cannot find symbol class DatePickerDialog
Gradle: error: cannot find symbol variable DatePickerDialog
Gradle: error: method does not override or implement a method from a supertype

I've been trying to fix this for 3 days now and have exhausted almost all of the similar question solutions I could find on here. I'm pretty confident with developing for android, not so confident with gradle and have probably done something obviously wrong.

Some extra info:

  • Android Studio v0.3.6
  • Android SDK Build-tools rev 19
  • Gradle version 1.8

Any ideas on how to fix this?

like image 357
Gyroscope Avatar asked Nov 21 '13 10:11

Gyroscope


People also ask

Why is my Gradle build failing?

If gradle --version works, but all of your builds fail with the same error, it is possible there is a problem with one of your Gradle build configuration scripts. You can verify the problem is with Gradle scripts by running gradle help which executes configuration scripts, but no Gradle tasks.

Why Android Studio is not running the app?

Unplug your device from the USB port on the computer. Restart the device by powering off and back on. Verify that Settings => Developer options => USB Debugging is enabled. Quit and re-launch Android Studio.

How do I fix gradle issues?

For this, you have to connect your PC to the internet and you have to open your Android studio. After opening your project click on the Sync Project with Gradle files option. This will automatically download the new Gradle files and will fix the issue which is caused by the Gradle files.


1 Answers

When Gradle builds the library project, it's building the release type even if you're building the debug type for your main app (this is a bug). In your library project, you have Proguard configured for your release build type, and Proguard is obfuscating the symbol names, making them invisible to your app.

Since you control the library code, the best thing is to not run Proguard in your library build, and just run it for release builds of your main app. It will obfuscate all code, including the dependencies.

If you really want to obfuscate the library code independently, you'll need to set up the Proguard rules to expose the public symbols of the library, DatePickerDialog being one.

like image 100
Scott Barta Avatar answered Sep 23 '22 03:09

Scott Barta