Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Support for app version #1

Closed
adesrosiers opened this issue Dec 14, 2016 · 11 comments
Closed

[Feature Request] Support for app version #1

adesrosiers opened this issue Dec 14, 2016 · 11 comments
Assignees
Milestone

Comments

@adesrosiers
Copy link

Would be awesome if this supported failing the build when a certain app version is reached:

@RemoveThis(version = "1.0.1")

@Stuie Stuie self-assigned this Dec 14, 2016
@Stuie Stuie modified the milestone: 0.0.2 Dec 14, 2016
@Stuie
Copy link
Owner

Stuie commented Dec 20, 2016

I believe this would require making a gradle plugin. I need to look into it before committing to it.

@vanniktech
Copy link

Read it from the BuildConfig ;)

@Jawnnypoo
Copy link

@vanniktech Would he be able to read the BuildConfig of the app, and not just the library's BuildConfig?

@vanniktech
Copy link

See which class was annotated with @RemoveThis and then get the package name of it. Then for each segment try getting the BuildConfig.

Imagine MyClass is annotated:
com.my.package.name.feature.ui.view.MyClass

then just try getting Buildconfig via:

com.my.package.name.feature.ui.view.BuildConfig
com.my.package.name.feature.ui.BuildConfig
com.my.package.name.feature.BuildConfig
com.my.package.name.BuildConfig
com.my.package.BuildConfig

at some point you'll get it and then you can go and use it.

@Jawnnypoo
Copy link

Heh, that could work. Although it would be problematic for if you have a seperate package name from your appId (such as if you were using an imported third party library or something).

Possibly you could also do something like context.getPackageName() since that will give you the apps package name and then assume the BuildConfig is under the same package name, though this is sometimes not true also if you are doing something like appending release or debug to the end of the package name on build flavors.

@vanniktech
Copy link

There is also this which is something they might work on and with it you'll get the application id

@Stuie
Copy link
Owner

Stuie commented Dec 23, 2016

At this point the library works for non-Android projects. The BuildConfig logic is something I thought of when @adesrosiers raised this issue, but wouldn't work for non-Android projects.

Potentially I could create an Android-specific package to provide version number support.

@Stuie
Copy link
Owner

Stuie commented Dec 25, 2016

I added support for self-managed milestones in version 0.0.3. I still need to investigate an Android-specific solution. I'm not entirely sure that the BuildConfig class is available at the point the annotationProcessor gets run, so it's not a trivial matter.

A gradle plugin may be worth looking into.

@Stuie
Copy link
Owner

Stuie commented Dec 27, 2016

Gradle supports annotationProcessorOptions, which allows you to pass arguments from your build.gradle to the annotationProcessor. The information I've found seems to talk about the JACK build chain for Android projects, which not everyone will have moved to by now.

I'm going to be away for a week, so I'm leaving this note for myself as a reminder of what I should look at when I return.

javaCompileOptions {
    annotationProcessorOptions {
        arguments = ['versionCode' : 'YOUR_VERSION_HERE']
    }
}

The GreenRobot EventBus supports such options.

@Stuie
Copy link
Owner

Stuie commented Dec 27, 2016

I got bored on my flight, so I had a quick go at implementing version code support. I've published 0.0.4-SNAPSHOT to the snapshot repository. The code is also available here on Github in the version-code branch.

If you're using this library in an Android project then you'll have to add the javaCompileOptions and annotationProcessorOptions sections to your build.gradle file, if you haven't already, in the defaultConfig section, as below:

android {
    defaultConfig {
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["versionCode" : "YOUR_VERSION_CODE_HERE"]
            }
        }
    }
}

Support for versionName is a bit more complicated. Some people use semantic versioning (e.g. 3.0.1), which shouldn't be too complicated, but people also use codenames, etc. which makes it very difficult to tell if a specific version is newer or older than another. @Milestones are better suited for that.

@Stuie Stuie added this to the 0.0.4 milestone Jan 4, 2017
@Stuie
Copy link
Owner

Stuie commented Jan 10, 2017

Just pushed version 0.0.4 with support for versionCode and versionName in the @RemoveThis and @Refactor annotations.

For Android projects you need to follow the instructions in the README. They're similar to my previous update on this issue, but I'll include a more complete version below for the sake of completeness.

android {
    defaultConfig {
        versionCode 4
        versionName "0.4.0"
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ['versionCode': String.valueOf(defaultConfig.versionCode),
                             'versionName': defaultConfig.versionName]
            }
        }
    }
}

You have to have a versionCode that can be parsed to an Integer, and the versionName has to adhere to the semantic versioning schema. This may not match up with what Android defaults to.

If there are problems then I may look to support other versioning schemas, but that complicates things a bit more than I'd like.

@Stuie Stuie closed this as completed Jan 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants