2015-04-07 40 views
5

Hi tôi đang cố gắng để buil và đổi tên tập tin aar tôi sử dụng gradle nhưng nhận được lỗi trên:Android thất bại trong việc đổi tên tập tin aar trong xây dựng

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={}}. 

Dưới đây là xây dựng đầy đủ của tôi kịch bản trên 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() 
     } 
    } 

Trả lời

3

Tôi nghĩ rằng bạn có thể có mã biến thể của mình ở sai địa điểm. Tôi đã thử các sau đây và nó làm việc cho tôi:

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

tôi đặt này ở một mức độ cao nhất về kết build.gradle, không thuộc buildTypes hoặc bất cứ điều gì khác, và tôi có thể thấy điều này:

You got to variant: com.and[email protected]3ab912fb and output: com.a[email protected]6441365a

You got to variant: com.and[email protected]dc7d23 and output: com.a[email protected]b9b8546

do đó, nó tìm thấy biến đầu ra và lặp lại trên nó.

Edit: Vì bạn muốn nguồn chính thức, đi đến 'Thao tác nhiệm vụ' phần ở đây: http://tools.android.com/tech-docs/new-build-system/user-guide

Từ trang web:

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) 
+0

Hãy để tôi làm việc này đi – jonney

+0

Vẫn không hoạt động. tôi gặp phải lỗi này: > Không thể tìm thấy thuộc tính 'đầu ra' trên com[email protected]f10d055. sẽ cập nhật bài đăng của tôi ở trên – jonney

+0

Bạn đã bỏ lỡ định nghĩa biến đầu ra, hãy nhớ thực hiện dòng thứ hai trong câu trả lời của tôi: "variant.outputs.each {output ->" –

4

Trước tiên, bạn tham khảo output đây:
def alignedOutputFile = output.outputFile

Tuy nhiên, bạn chưa khai báo, đó là lý do tại sao bạn nhận được cảnh báo rằng Gradle Could not find property 'output'.

Bạn cần phải hoặc lặp qua các output s thuộc của bạn variant như trong this post:

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

hoặc hoàn toàn đủ điều kiện nó, ví dụ
def alignedOutPutFile = variant.outputs[0].outputFile

+0

muốn tôi cũng có thể đánh dấu câu trả lời của bạn là câu trả lời đúng nhưng tôi đánh dấu Daniels một khi anh ấy giúp tôi hiểu thêm về vấn đề này là gì. Dù sao cũng cảm ơn bạn – jonney

Các vấn đề liên quan