2016-09-30 108 views
1

直到最新的Android Studio和Gradle插件更新(均爲2.2),此代碼在構建庫之前清理了我的輸出文件夾,並在最終歸檔之後複製了它。現在,它失敗,錯誤「無法獲取未知屬性'的項目'的工具':工具類型爲org.gradle.api.Project。」的assembleDebug。「assembleDebug無法識別(Android Studio 2.2,Gradle插件2.2)

有幾個相似但不相同的問題,我之前讀過的文章。

是否有任何修復,方法或完全不同的方式來做我想做的事情?

apply plugin: 'com.android.library' 

android { 
    compileSdkVersion 24 
    buildToolsVersion '24.0.0' 
    defaultConfig { 
     minSdkVersion 16 
     targetSdkVersion 24 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
    productFlavors { 
    } 
} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    compile 'com.android.support:appcompat-v7:24.0.0' 
    compile 'com.android.support:design:24.0.0' 
} 

task cleanBuildDirAndOut(type: Delete) { 
    delete buildDir 
    delete '../OUT/tools.aar' 

    doLast { 
     println ('Deleted Tools buildDir') 
     println ('Deleted tools.aar') 
    } 
} 

task copyLibDebug(type: Copy) { 
    from 'build/outputs/aar/Tools-debug.aar' 
    into '../OUT' 
    rename ('Tools-debug.aar', 'tools.aar') 

    doLast { 
     println ('Copied tools.aar (debug) to Out') 
    } 
} 

assembleDebug.dependsOn copyLibDebug 
preBuild.dependsOn cleanBuildDirAndOut 
+0

*有幾個類似但不相同的問題*添加'assembleDebug'任務時添加任務的解決方案不起作用? – Selvin

+0

對不起,你在想什麼解決方案? – Darko

+0

以'tasks.whenTaskAdded'開頭的那個 – Selvin

回答

3

這並沒有解決不承認assembleDebug的問題,但它解決了我的問題是如何建立

gradle.buildFinished { 
    copyLibDebug.execute() 
} 
相關問題