Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
582 views
in Technique[技术] by (71.8m points)

gradle - 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:lahlahMyClass.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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...