Подтвердить что ты не робот

Не удалось найти свойство 'outputFile' на com.android.build.gradle.internal.api.ApplicationVariantImpl

После обновления до AS 1.0 RC 1 и плагина 0.14.4 у меня возникают проблемы с частью переименования моего build.gradle:

applicationVariants.all { variant ->
            def file = variant.outputFile
            variant.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
        }

теперь бросается:

Error:(78, 0) Could not find property 'outputFile' on com.and[email protected]67e7625f.

а также я не могу перейти к классу ApplicationVariantImpl, чтобы посмотреть, как свойство могло быть переименовано. Кто-нибудь знает обходные пути для этого?

4b9b3361

Ответ 1

попробуйте это

applicationVariants.all { variant ->
    variant.outputs.each { output ->
        def file = output.outputFile
        output.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
    }
}

Ответ 2

Более подробно:

applicationVariants.all { variant ->
    variant.outputs.each  { output ->
        output.outputFile = new File(output.outputFile.parent, output.outputFile.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
    }
}

Ответ 3

Это может произойти по нескольким причинам:

1.) Сначала, как было сказано ранее, @Халидов, попробуйте

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

2.) Вторая попытка обновить все другие плагины.

Например, я получил эту проблему для Spoon, которая была решена с помощью обновления Spoon до:

classpath 'com.stanfy.spoon:spoon-gradle-plugin:0.14.1'

Ответ 4

Или где есть только один вариант:

def apk = outputs[0].outputFile

Вместо

def apk = variant.outputFile

Ответ 5

Убедитесь, что вы используете последнюю версию gradle (а не плагин, gradle он сам).

Проверьте gradle-wrapper.properties. Вы используете gradle 2.1?

Дополнительная информация о совместимости: http://tools.android.com/tech-docs/new-build-system/version-compatibility

Ответ 6

Мне удалось решить следующее:

старый:

buildTypes { 
libertação {

    runProguard false  // esta linha tem que ser mudado

    proguardFiles getDefaultProguardFile ( 'android.txt proguard-' ),  'proguard-rules.pro' 
} 

}

новый

buildTypes { 
libertação {

    minifyEnabled false  // nova versão

    proguardFiles getDefaultProguardFile ( 'android.txt proguard-' ),  'proguard-rules.pro' 
} 

}

отредактирован в файле buil.gradle вашего проекта, как описано в этом сообщении ruan65 Ошибка: (26, 0) Gradle Метод DSL не найден: 'runProguard()'

и после редактирования тоже эта строка:

applicationVariants . all { variant -> 
variant . outputs . each { output -> 
    def file = output . outputFile 
    output . outputFile =  new  File ( file . parent , file . name . replace ( ".apk" ,  "-"  + defaultConfig . versionName +  ".apk" )) 
} 

}

как там было сказано. Это успокоило меня!