Adding PubNub AnnotationProcessor in Android Studio - java

I'm trying to set up the PubNub jar as a library in my Android Studio project. The project is something I am porting over from another computer, so I'm mostly copying things in.
It appears between then and now that I now have to configure the AnnotationProcessor of this jar, but I'm really not sure what that requires, nor have I been able to find an example that fits my issue.
When I try to compile my project, I am left with this message:
Error:FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:javaPreCompileDebug'.
Annotation processors must be explicitly declared now.
The following dependencies on the compile classpath are found to contain annotation processor.
Please add them to the annotationProcessor configuration- pubnub-gson-4.19.0-all.jar (pubnub-gson-4.19.0-all.jar).
Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior.
Note that this option is deprecated and will be removed in the future.
See https://developer.android.com/r/tools/annotation-processor-error- message.html for more details.
I'm really not sure at all what this is telling me to do, and the examples I can find of annotationprocessor on the internet (none for PubNub) all are pointing to packages and classes, which I don't see what I am suppose to do with.
Can someone lead me down the correct path?
I apologize for the formatting of the error, but the site wouldn't let me submit it in blockquotes because it was "improperly formatted code."

Try to add this line in your dependencies{} block:
annotationProcessor files('libs/pubnub-gson-4.19.0-all.jar')
(along with the implementation files('libs/pubnub-gson-4.19.0-all.jar'))
It works in my case.

Related

Execution failed for task ':app:dataBindingMergeDependencyArtifactsDebug'

I added this library from GitHub into my android app:
implementation 'com.github.quiin:unifiedContactPicker:1.0'
Now, this library uses other libraries from GitHub.
When I run my app, it tells me that these internal libraries are not found, so I dig them up and find their dependencies and add them to my app's Gradle file. But the problem is that they are not being detected and this is the error I am getting both times.
Execution failed for task ':app:dataBindingMergeDependencyArtifactsDebug'.
Could not resolve all files for configuration ':app:debugCompileClasspath'.
Could not find com.hootsuite.android:nachos:1.0.0.
Required by:
project :app > com.github.quiin:unifiedContactPicker:1.0
Possible solution:
Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
Please help, I have been stuck at this for a long time and I need to use this dependency. I have also tried using similar dependencies that fulfil my purpose but they all seem to have the same problem. So I don't know if there's a problem with my project or the libraries.
I had the same problem but with geok library. I checked syntax of dependencies declaration lines on JitPack website and there were different than I had on my build.gradle file. Finally I changed
from:
implementation "com.github.piruin:geok:$geokVersion"
implementation "com.github.piruin.geok-gson:$geokVersion"
to:
implementation "com.github.piruin.geok:geok:$geokVersion"
implementation "com.github.piruin.geok:geok:$geokVersion"
and it works.

Including javax persistence in a Cordova/Android project

I am trying to incorporate ObjectBox in my hybrid Cordova/Android project. By dint of some trial and error I have managed to figure out two of the steps involved.
The app level build.gradle file has to be modified to include the ObjectBox Gradle plugin classpath "io.objectbox:objectbox-gradle-plugin:2.5.0"
Define a build-extras.gradle file to "apply" the ObjectBox plugin ext.postBuildExtras = {apply plugin: 'io.objectbox'}
The next step according to the ObjectBox docs is to define at least one Entity class
However, the issue here is that I need to import the javax.persistence.* classes into the project. It is not clear to me how I do this. I have run into suggestions along the lines of including
compile group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
in the dependencies section of the app level build.gradle file. However, this causes gradle to complain that it does not know the compile() function. I'd be much obliged to anyone who might be able to tell me how this should be done.
For the benefit of anyone running into this thread - you can download the JAR file for javax.persistence here. Place this line in the folder src/android/libsof your custom plugin and then modify plugin.xmlwith the line
<lib-file src='src/android/libs/name-of-javax-persistence.jar'/>

Android Studio not excluding a transitive dependency and complains about class conflict

Hi I'm working on an Android app and I need to use a library called Semantics3. The issue I'm having is that the Semantics3 library depends on a few different libraries one of which is org.json but Android Studio automatically includes its own unique version of org.json which causes various issues. I've tried a few things to work around this and I'll describe them below.
First, I just imported the Semantics3 library. All the code compiles but when code from the library runs to make a service call the app crashes. This is due to a "NoSuchMethod" error because Semantics3 makes use of a constructor from a class in org.json which the AS version doesn't include.
To get around this I made my own jar file of the Semantics3 code and add in the dependencies it needs on my own in Gradle. The app still crashes, though not because it can't find the constructor. In this case the error is due to an exception from org.json, specifically "org.json.JSONException: Value com.android.okhttp.internal.huc.HttpURLConnectionImpl of type java.lang.String cannot be converted to JSONObject". I couldn't figure out why this error was popping up so I decided to try out the Semantics3 library outside of Android and just made a simple Maven project. In the Maven project I can make service calls just fine with no issue, but if I add the jar file and dependencies on my own, I get the same error as in AS.
So I figure there's something missing in the source code on Github that I used to make the jar or something but that's beyond me to figure out, so I'm back at trying to just import the library. My final and current attempt involves trying to explicitly import the version of org.json that Semantics3 needs along with the Semantics3 library in Gradle. But when I bring in the Sematnics3 library I try to exclude the transitive dependency Semantics3 introduces to org.json. I've included the Gradle file for this attempt below.
// https://mvnrepository.com/artifact/com.semantics3/Sem3Java
implementation('com.semantics3:Sem3Java:1.2.4'){
exclude group:'org.json:json'
}
implementation 'org.json:json'
constraints {
implementation(group: 'org.json', name: 'json', version: '20190722') {
because 'Semantics3 requires version 20190722 of org.json, not the default AS version'
}
}
The issue is when I try to run the code with the above setup in Gradle I get an error saying there are duplicate class definitions contained in the Semantics3 library and org.json library. And yes there are certainly conflicts but I thought the exclude bit to the Semantics3 implementation would be enough to prevent that from happening. Did I make a mistake somewhere or am I misunderstanding or misusing the exclude? If it makes a difference it appears the Semantics3 library does hardcode the org.json library into its Jar file. I appreciate any help with this. Thank you.

gradle: best way to encapsulate custom dsl

my screencast, i hope my aExtFunc can work in build.gradle in any projects, but intellij idea raise
Cannot resolve symbol 'gradleExt'
my question is: how to fix it.
Defining dependency on the project
dependencies{
compile project(':gradleExt')
}
Doesn't mean that you can work with the content of the project in your build script:
task ATask() {
new gradleExt.Ext().aExtFunc()
}
You probably need to create new groovy class directly in the build.gradle file implementing desired behaviour. Or if you really want to have the implementation in different place you need to add the classpath dependecy into the buildScript{} block. See the documentation on implementing custom tasks:
http://www.gradle.org/docs/current/userguide/custom_tasks.html
If you want custom dsl, then custom gradle plugin is probably what you are looking for
http://www.gradle.org/docs/current/userguide/custom_plugins.html
And also please double check the documentation on multi-project builds if that might be of any use to you, it is not clear from the "my screencast" what your overall gradle setup is. I would post the link, but I don't have enough reputation.

Could not find property 'allJava' on source set main

Hy, I am using Android Studio 0.6.0 as of this morning, during the upgrade process I had to switch to Gradle version 0.11 to compile my Android project.
Ever since I get this annoying error which prevents me from building my project.
Error:Could not find property 'allJava' on source set main.
This property is defined only for the 'java' plugin, but I am using the 'android' plugin in my build.gradle file, so I see no reason why I should receive this error.
Does anyone know how to get rid of this message?
UPDATE:
I solved it, it seems this property is no longer available in Gradle 0.11.1, and somebody somewhere in my project was using it.
I found this line in one of the build.gradle files:
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
which made a reference to another gradle configuration file, that used this property to make a task of generating JavaDocs for every .java file.
So in order to solve this problem, just look everywhere in your code for a reference to this property.
In case anyone happens upon this thread, I did a little investigating into the Gradle Android plugin source.
It appears that the allJava property was removed as it was redundant with the java property. Swapping allJava out for 'java' seems to fix the issue.
https://android.googlesource.com/platform/tools/base/+/5e71a83f74258b85d7f5306bf743c4d69d6242f8%5E%21/#F2
Consequently, the allSource property was also removed, which will break the gradle-mvn-push script as well. I have submitted a bug report for that one, linked below.
https://code.google.com/p/android/issues/detail?id=71174

Categories

Resources