1

Gradle compiles fine with the following build.gradle file:

apply plugin: 'com.android.library'
android {
    compileSdkVersion 21
    buildToolsVersion "22.0.1"
    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 16
        versionCode 1
        versionName "1.0"
    }
   sourceSets {

        debug {
            jniLibs.srcDirs = ['src/main/jniLibs-dbg']
            res.srcDirs = ['src/main/res-dbg', 'src/main/res-common']
        }
        release {
            jniLibs.srcDirs = ['src/main/jniLibs-rel']
            res.srcDirs = ['src/main/res-rel', 'src/main/res-common']
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

    }
    lintOptions {
        abortOnError false
    }
}
dependencies {
    compile 'com.android.support:support-v4:23.0.0'
    debugCompile files('libs/debug.jar')
    releaseCompile files('libs/nonDebug.jar')
}

But, when I add productFlavors, compilation fails:

productFlavors {
        flavor1{

        }
        flavor2{

        }
    }

The flavors are empty intentionally. I just want to see whether compilation succeeds. Later I will add resources per flavour. The console log indicates that the assembleDebug task fails because it can't find the class files which are inside debug.jar

This is the error I see:

What went wrong:

Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.

Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Any idea?

Student
  • 43
  • 6

2 Answers2

1

Whats your Logcat Throws

Note: Some input files use or override a deprecated API.

At First upgrade your buildToolsVersion & compileSdkVersion .

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
    minSdkVersion 8
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}

You can change your minSdkVersion 8 level , Use 15 & set targetSdkVersion 23.

Again for

Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.

You may visit here

Failure on build with Gradle on command line with an android studio project : Xlint error

Community
  • 1
  • 1
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

The problem is

apply plugin: 'com.android.library

The key part is to set publishNonDefault to true in library build.gradle, Then you must define dependencies as suggested by user guide.

publishNonDefault true
productFlavors {
    flavor1{}
    flavor2{}
}

Also you are applying the flavors to the library so you also need to define on project gradle which flavour library you are going to use in the project

for e.g.

market1Compile project(path: ':lib', configuration: 'flavor1Release')
market2Compile project(path: ':lib', configuration: 'flavor2Release')

For the more detail please check the following link

Multi flavor app based on multi flavor library in Android Gradle

Let me know if you found any issues on that i will help on that also

Community
  • 1
  • 1
Sandy
  • 985
  • 5
  • 13
  • Thanks Sandy, but unfortunately it did not solve the issue. – Student Nov 16 '15 at 13:19
  • The problem is that all Java fiels which reside in debug.jar and are referenced from within the app, can not be found. The compiler shouts that the package x.y.x does not exist. The problem is related to the dependencies but only shows up if I have productFlavors. – Student Nov 16 '15 at 13:21
  • Unfortunately I have not gotten the solution yet.. :-( Still struggling with it. I am thinking the problem has to do with the dependencies. How would addding a productFlavor have any effect on the dependency?.... Beats me... – Student Nov 16 '15 at 13:36
  • Yes it will effect on the project dependencies on which you are going to use this library so you need to decide which flavor library you want on the project you can define that on project dependecy – Sandy Nov 16 '15 at 13:48
  • Sandy, thanks to your help ,I just noticed that the Android library builds fine, and that the failure is with the app compiling with the library. – Student Nov 16 '15 at 14:22
  • @Student if you feel my answer was correct and it helps you then please make it the right answer by clicking the check mark so others also get some help from here. Thanks – Sandy Nov 17 '15 at 06:05
  • Is it possiblem to compile the app to have the same flavor both in debug and release mode, rather than what you suggested above: market1Compile project(path: ':lib', configuration: 'flavor1Release') market1Compile project(path: ':lib', configuration: 'flavor1Debug') – Student Nov 17 '15 at 12:07
  • library project not compiled with product flavors configuration . – Chetan Joshi Jun 05 '17 at 06:41