Gradle Autoincrement and Rename APK I/O Error

好久不见. 提交于 2019-12-10 14:46:25

问题


I'm trying to do an auto increment for the build number in Android Studio. Followed this link, and it worksfine.

Now I want to rename the apk using the versionName. I also did that successfully, as I can see in my app\build\outputs\apk directory, that the file is there.

The problem The generated apk and the part where Android Studio you see the "local path" don't have the same file name.

The generated apk's name: MyAppsName-v1.0-64-debug.apk

The "local path" it's looking for: ..\app\build\outputs\apk\MyAppsName-v1.0-60-debug.apk

So it makes sense to see an error saying "Local path doesn't exist." Because the "MyAppsName-v1.0-60-debug.apk" does not exist.

Here's the snippet of my build.gradle:

 def versionPropsFile = file('version.properties')

if (versionPropsFile.canRead()) {
    def Properties versionProps = new Properties()

    versionProps.load(new FileInputStream(versionPropsFile))
    def value = 0
    def runTasks = gradle.startParameter.taskNames
    if ('assemble' in runTasks || 'assembleRelease' in runTasks || 'aR' in runTasks) {
        value = 1;
    }

    def versionMajor = 1
    def versionMinor = 0
    def versionBuild = versionProps['VERSION_BUILD'].toInteger() + 1
    def version_Code = versionProps['VERSION_CODE'].toInteger() + value

    versionProps['VERSION_BUILD'] = versionBuild.toString()
    versionProps['VERSION_CODE'] = version_Code.toString()

    versionProps.store(versionPropsFile.newWriter(), null)

    defaultConfig {
        versionCode version_Code
        versionName "v${versionMajor}.${versionMinor}-${versionBuild}"
        minSdkVersion 15
        targetSdkVersion 21
    }


    archivesBaseName = "MyAppsName" + "-" + defaultConfig.versionName;
} else {
    throw new GradleException("Could not read version.properties!")
}

来源:https://stackoverflow.com/questions/30082087/gradle-autoincrement-and-rename-apk-i-o-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!