Android javax.annotation.processing Package missing
Asked Answered
T

10

29

I would like to do some annotation processing based on the example in the following link: http://www.zdnetasia.com/writing-and-processing-custom-annotations-part-3-39362483.htm.

However, I would like to implement this in my Android project, and it seems I cannot use the package with the android platform. Do I need to add an external jar or is there something I'm missing?

Thanks.

Twoup answered 10/3, 2012 at 22:39 Comment(0)
S
11

The javax.annotation.processing package is not included in Android, but the Android VM team describes how to include extra javax packages here - it might be applicable to your question.

Sway answered 10/3, 2012 at 22:45 Comment(2)
Cannot see the linked solution. That's why we should quote/copy/refer instead of plain linkingBarranquilla
Updated the link for reference. For the record, the linked guide uses an old version of Android (with Ant build scripts); you'd want the gradle solutions in the other answers.Tetherball
D
23

The javax.annotation.processing package is not included in Android. You don't need to include this inside your compiled app module. You just need this dependency for your compiler/processor module during build time. Therefore, inside your app's build.gradle you should add the following after including your annotation processor:

provided 'org.glassfish:javax.annotation:10.0-b28'
Dosh answered 7/7, 2015 at 15:10 Comment(2)
Configuration 'provided' is obsolete and has been replaced with 'compileOnly'Knighterrantry
javax.annotation.processing is not in this Glassfish dependency either. It has the right annotations, but in javax.annotation package.Whitewood
F
17

There is a much easier way if you use Android Studio / Gradle.

I found the following looking through the answers of the question How do I add javax.annotation.Generated to Java SE 5?:

For a Gradle build the dependency should be

compile 'org.glassfish:javax.annotation:10.0-b28'

Fromma answered 2/11, 2014 at 20:15 Comment(0)
S
11

The javax.annotation.processing package is not included in Android, but the Android VM team describes how to include extra javax packages here - it might be applicable to your question.

Sway answered 10/3, 2012 at 22:45 Comment(2)
Cannot see the linked solution. That's why we should quote/copy/refer instead of plain linkingBarranquilla
Updated the link for reference. For the record, the linked guide uses an old version of Android (with Ant build scripts); you'd want the gradle solutions in the other answers.Tetherball
G
9
implementation 'org.glassfish:javax.annotation:10.0-b28'
compileOnly 'com.github.pengrad:jdk9-deps:1.0'

Add these two dependencies in your build.gradle file, this will work.

Galba answered 2/7, 2021 at 8:25 Comment(0)
T
3

compileOnly 'org.glassfish:javax.annotation:10.0-b28'

Toscano answered 13/4, 2018 at 9:40 Comment(1)
Worked like a charm!Sunup
R
2

Simply adding compile 'javax.annotation:javax.annotation-api:1.2' should do the trick.

see here for all available versions: https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api

Radiograph answered 31/3, 2016 at 12:41 Comment(0)
B
2

for kotlin DSL you need to use compileOnly("org.glassfish:javax.annotation:10.0-b28")

for groovy DSL you need to use compileOnly 'org.glassfish:javax.annotation:10.0-b28'

Bulbil answered 8/6, 2020 at 12:4 Comment(0)
S
0

I also faced same issue. So generally we will face this issue when our jdk version will be 8+ . So for jdk8+ you just need to add below dependency in your build.gradle(:app) file.

compileOnly 'com.github.pengrad:jdk9-deps:1.0'

It will work like a charm. Please give it a try!

Shock answered 11/10, 2022 at 13:37 Comment(1)
There is an answer with same solution for the same question.Lacker
S
0

This works for me compileOptions { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 }

Secrecy answered 18/3 at 7:18 Comment(0)
B
-4

I find a method in butterknife. Add this in build.gradle:

compile files(org.gradle.internal.jvm.Jvm.current().getJre().homeDir.getAbsolutePath()+'/lib/rt.jar')
Bromic answered 30/3, 2017 at 7:15 Comment(1)
This is evil. This way you are adding the entire jre as dependencyCrossstitch

© 2022 - 2024 — McMap. All rights reserved.