5

Hi i am trying to buil and rename my aar file using gradle but get the above error:

A problem occurred evaluating project ':app'.
> Could not find property 'outputs' on BuildType_Decorated{name=variant, debuggable=false, testCoverageEnabled=false, jniDebuggable=false, pseudoLocalesEnabled=false, renderscriptDebuggable=false, renderscriptOptimLevel=3, applicationIdSuffix=null, versionNameSuffix=null, minifyEnabled=false, zipAlignEnabled=true, signingConfig=null, embedMicroApp=true, mBuildConfigFields={}, mResValues={}, mProguardFiles=[], mConsumerProguardFiles=[], mManifestPlaceholders={}}.

Here is my full build script on gradle

 apply plugin: 'com.android.library'

android.libraryVariants.all { variant ->
    def alignedOutputFile = output.outputFile
    def unalignedOutputFile = output.packageApplication.outputFile

    logger.warn('You got to variant: ' + variant + ' and output: ' + output)
    // Customise APK filenames (to include build version)
    if (variant.buildType.zipAlignEnabled) {
        // normal APK
        output.outputFile = new File(alignedOutputFile.parent, alignedOutputFile.name.replace(".aar", "-" + defaultConfig.versionName + "-" + defaultConfig.versionCode + ".aar"))
    }
    // 'unaligned' APK
    output.packageApplication.outputFile = new File(unalignedOutputFile.parent, unalignedOutputFile.name.replace(".aar", "-" + defaultConfig.versionName + "-" + defaultConfig.versionCode + ".aar"))

}

    android {
        compileSdkVersion 21
        buildToolsVersion '21.1.2'

        repositories {
            flatDir {
                dirs 'libs'
            }
        }



        defaultConfig {
            minSdkVersion 14
            targetSdkVersion 21
            versionCode 1
            versionName "1.0"
        }
        buildTypes {

            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    /*
      Both Joda-Time imports have these 2 files and they conflict with each other.  'exclude' is
      the workaround.
    */
    android.packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:21.0.3'
        compile(name: 'etsdk-3.5.0', ext: 'aar')
        // 3rd Party Libraries Required for SDK integration
        compile 'com.fasterxml.jackson.core:jackson-annotations:2.4.4'
        compile 'com.fasterxml.jackson.core:jackson-databind:2.0.6'
        compile 'org.joda:joda-convert:1.7'
        compile 'joda-time:joda-time:2.6'
        compile 'com.j256.ormlite:ormlite-android:4.48'
        compile 'com.j256.ormlite:ormlite-core:4.48'
        compile 'com.belladati:httpclientandroidlib:4.3.0'
        compile 'com.radiusnetworks:AndroidIBeaconLibrary:0.7.6'
        compile 'com.google.android.gms:play-services:4.0.30'
    }

    // 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.1.+'

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

    allprojects {
        repositories {
            jcenter()
        }
    }
Jono
  • 17,341
  • 48
  • 135
  • 217

2 Answers2

4

You first reference output here:
def alignedOutputFile = output.outputFile

However, you haven't declared it, which is why you get a warning that Gradle Could not find property 'output'.

You need to either loop through the outputs belonging to your variant like in this post:

android.libraryVariants.all { variant ->
    variant.outputs.each { output ->
        output.outputFile = ...        
    }
}

or fully qualify it, e.g.
def alignedOutPutFile = variant.outputs[0].outputFile

Community
  • 1
  • 1
Justin Garrick
  • 14,767
  • 7
  • 41
  • 66
  • wish i could also mark your answer as the correct one but i marked Daniels one as he helped me understand more on what was the issue. Thanks anyway – Jono Apr 16 '15 at 15:35
3

I think you might have your variant code in the wrong place. I tried the following and it worked for me:

android.applicationVariants.all { variant ->
    variant.outputs.each{ output ->
        logger.warn('You got to variant: ' + variant + ' and output: ' + output)
    }
}

I put this at a top level on the build.gradle, not under buildTypes or anything else, and I can see this:

You got to variant: com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated@3ab912fb and output: com.android.build.gradle.internal.api.ApkVariantOutputImpl_Decorated@6441365a

You got to variant: com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated@dc7d23 and output: com.android.build.gradle.internal.api.ApkVariantOutputImpl_Decorated@b9b8546

so it does find the outputs variable and iterates over it.

Edit: Since you want official sources, go to the 'Manipulating tasks' section here: http://tools.android.com/tech-docs/new-build-system/user-guide

From the site:

In Android projects, this is a bit more complicated because there could be a large number of the same task and their name is generated based on the Build Types and Product Flavors.

In order to fix this, the android object has two properties:

applicationVariants (only for the app plugin)
libraryVariants (only for the library plugin)
testVariants (for both plugins)
Daniel A. González
  • 1,225
  • 8
  • 11
  • Still did not work. i get this error: > Could not find property 'output' on com.android.build.gradle.internal.api.LibraryVariantImpl_Decorated@f10d055. will update my post above – Jono Apr 16 '15 at 10:10
  • You missed defining the output variable, remember to do the second line in my response: "variant.outputs.each{ output ->" – Daniel A. González Apr 16 '15 at 13:51
  • 1
    No problem! Also, I don't know if it was just a mistake on your part or you feel lost with Groovy and Gradle in general, but if it is the latter, I suggest you check this video: https://www.youtube.com/watch?v=fHhf1xG0pIA It explains what Groovy is, how it relates to Java, and how Gradle uses Groovy. It really helped me understand all of this. – Daniel A. González Apr 16 '15 at 21:32
  • O nice. Yea i will Check it out. Really clueless with groovy syntax! – Jono Apr 16 '15 at 23:25