Why Vert.x codegen fails to create rx-fied classes? - java

For some reason my 4.0.2 based code doesn't produce rx-fied service versions with codegen.
Both VertxEBProxy and VertxProxyHandler classes are created as expected though.
Here is a demo project: https://github.com/ashertarno/playground
Please see the required dependencies below:
implementation "io.vertx:vertx-core:$vertxVersion"
implementation "io.vertx:vertx-rx-java2:$vertxVersion"
implementation "io.vertx:vertx-codegen:$vertxVersion"
implementation "io.vertx:vertx-service-proxy:$vertxVersion"
implementation "io.vertx:vertx-rx-java2-gen:$vertxVersion"
annotationProcessor "io.vertx:vertx-codegen:$vertxVersion:processor"
annotationProcessor "io.vertx:vertx-service-proxy:$vertxVersion"
What would be missing in this case?

You have to add io.vertx:vertx-rx-java2-gen:$vertxVersion as an annotationProcessor and testAnnotationProcessor. After I did that, I had the classes get generated:
./build/classes/java/main/me/tarno/playground/reactivex/BaseServiceProxy.class
./build/classes/java/test/me/tarno/playground/reactivex/TestProxy.class

Related

Why #ContributesAndroidInjector cant be found by DaggerAndroidProcessor library on the processor path?

I am implementing Dagger2 and when I am using #ContributesAndroidInjector, I get compile time
error:#dagger.android.ContributesAndroidInjector was used,but dagger.android.processor.AndroidProcessor was not found on the processor path
I tried multiple solutions but this error never goes away. I tried using old library
version of dagger2 dependencies. I tried creating a java abstract #Module class. I
tried using Kotlin android processor declaring kapt dependency, But Nothing really Helped. Can somebody please help me to rid of this error. Following are the dependencies of Dagger2 that I am using in my project for reference:
implementation "com.google.dagger:dagger:2.35.1"
implementation "com.google.dagger:dagger-android:2.35.1"
implementation "com.google.dagger:dagger-android-support:2.35.1"
annotationProcessor "com.google.dagger:dagger-android-processor:2.35.1"
kapt 'com.google.dagger:dagger-compiler:2.28.3'
implementation 'javax.inject:javax.inject:1'
kapt "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.3.0"
implementation "androidx.compose.runtime:runtime:1.2.1"
Oh! You were not using the same Dagger compiler as your implementations. Your compiler was 2.28.3 and your implementations were 2.35.1. If the Dagger compiler has a different version than its implementation, it may generate non-working code that refers to missing implementations, or (as here) it may not generate code at all.
Make them match:
implementation "com.google.dagger:dagger:2.35.1"
implementation "com.google.dagger:dagger-android:2.35.1"
implementation "com.google.dagger:dagger-android-support:2.35.1"
kapt "com.google.dagger:dagger-android-processor:2.35.1"
kapt "com.google.dagger:dagger-compiler:2.35.1"
implementation 'javax.inject:javax.inject:1'
kapt "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.3.0"
implementation "androidx.compose.runtime:runtime:1.2.1"
I also switched your Android compiler to kapt per the Dagger README section on Gradle.
I managed to solve this by changing my dependencies to the following-
implementation 'com.google.dagger:dagger-android:2.16'
implementation 'com.google.dagger:dagger-android-support:2.16'
kapt "com.google.dagger:dagger-compiler:2.16"
kapt "com.google.dagger:dagger-android-processor:2.16"
This seems to be more like a a hack than a proper solution as when I update my libraries it starts giving me compile time error

not able to build android project with butterknife dependency

I am not able to build android project due to error of butterknife dependency.
ERROR
Execution failed for task ':app:javaPreCompileDebug'.
Could not resolve all files for configuration ':app:debugAnnotationProcessorClasspath'.
Failed to transform butterknife-compiler-8.6.0.jar (com.jakewharton:butterknife-compiler:8.6.0) to match attributes
{artifactType=processed-jar, org.gradle.category=library,
org.gradle.libraryelements=jar, org.gradle.status=release,
org.gradle.usage=java-runtime}.
> Execution failed for JetifyTransform: /Users/jordan/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife-compiler/8.6.0/d3defb48a63aa0591117d0cec09f47a13fffda19/butterknife-compiler-8.6.0.jar.
> Failed to transform '/Users/jordan/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife-compiler/8.6.0/d3defb48a63aa0591117d0cec09f47a13fffda19/butterknife-compiler-8.6.0.jar'
using Jetifier. Reason: AmbiguousStringJetifierException, message: The
given artifact contains a string literal with a package reference
'android.support.v4.content' that cannot be safely rewritten.
Libraries using reflection such as annotation processors need to be
updated manually to add support for androidx.. (Run with --stacktrace
for more details.)
This is a known exception, and Jetifier won't be able to jetify this library.
Suggestions:
- If you believe this library doesn't need to be jetified (e.g., if it already supports AndroidX, or if it doesn't use support
libraries/AndroidX at all), add android.jetifier.blacklist =
{comma-separated list of regular expressions (or simply names) of the
libraries that you don't want to be jetified} to the gradle.properties
file.
- If you believe this library needs to be jetified (e.g., if it uses old support libraries and breaks your app if it isn't
jetified), contact the library's authors to update this library to
support AndroidX and use the supported version once it is released.
If you need further help, please leave a comment at
Dependency in Gradle Build File in App Level
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.2.0-beta02'
implementation 'com.melnykov:floatingactionbutton:1.3.0'
// implementation 'com.android.support:design:28.0.0'
// implementation 'com.android.support:support-v13:28.0.0'
implementation 'com.jpardogo.materialtabstrip:library:1.0.6'
implementation 'com.jakewharton:butterknife:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
}
how should I resolve it ?
Please note that, as per official documentation the Butter Knife tool is now deprecated.
And they have recommended to switch to View Binding.
Hence, I request you to revisit your decision of using Butter Knife.
And in your gradle files, please ensure that below lines are added properly.
Add these changes and then click on File > Invalidate Cache and Restart in Android Studio.
android {
...
// Butterknife requires Java 8.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Dependency
dependencies {
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
}
If you are using Kotlin, replace annotationProcessor with kapt.
And to use Butter Knife in a library, please follow the steps provided in section Library Projects inside official documentation

Android Studio class file for com.google.common.util.concurrent.ListenableFuture not found

I cannot build my project due to it failing because it cannot find a class. Is there something wrong with my sdk or dependancies?
I have tried invalidating cache and restarting. I am using api 29.
The following is where the error shows up
public class PodcastUpdateWorker extends Worker {
}
Here is the error printout
/home/snowman/AndroidStudioProjects/CorbettReportPodcasts/app/src/main/java/com/example/corbettreportpodcasts/PodcastUpdateWorker.java:36: error: cannot access ListenableFuture
public class PodcastUpdateWorker extends Worker {
^
class file for com.google.common.util.concurrent.ListenableFuture not found
and my dependancies
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'com.google.android.exoplayer:exoplayer-core:2.12.0'
implementation 'com.google.android.exoplayer:exoplayer-dash:2.12.0'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.12.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
implementation "androidx.room:room-runtime:2.2.5"
annotationProcessor "androidx.room:room-compiler:2.2.5"
testImplementation "androidx.room:room-testing:2.2.5"
implementation 'androidx.work:work-runtime:2.4.0'
implementation 'com.google.android.material:material:1.2.1'
}
any help is appreciated
There is an issue with the exoplayer library conflicting with listenablefuture causing it not to be found. READ MORE
you can include guava implementation 'com.google.guava:guava:29.0-android' to fix this
implementation "androidx.concurrent:concurrent-futures:1.1.0"
Reference: https://developer.android.com/jetpack/androidx/releases/concurrent
Check for the package name in gradle scripts (module:app) and in ...app>src>main>java.
Rename the folder to the desired package name. Make sure that the package name is changed in all the java files also. After renaming, sync your project with gradle files.
If you are doing this after the first Gradle sync, then this trick may not work. You need to change them manually.
I solved it by updating
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
to
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
also update these to latest versions, if applicable
api 'androidx.core:core-ktx:1.3.2'
api "org.jetbrains.kotlin:kotlin-stdlib:1.4.32"
In addition to the accepted answer. I didn't user Exoplayer in the application. After digging deeper I found that if you use Google's library for guava to fix conflicts like this:
implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
This will also cause an issue. Removing this dependency solved the problem. BUT on the other hand, if you use some library, which causes the problem with listenablefeature in opposite adding this dependency solves the problem.

How to resolve org.postgresql.jdbc.PgConnection.createClob() is not yet implemented

The exception
When starting spring-boot application I've received:
Caused by: java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc.PgConnection.createClob() is not yet implemented.
I know this is related to some issue from Postgresql driver, which I am using now.
Unsucessful attempt
Many people resolved the problem just putting this following line in application.properties file:
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=true
I still have the same issue. Is there any other tip for It? In case thinking about see my project with current configuration:
https://github.com/caliari77/hiRank
After some tests I could resolve this. It seems Hibernate implementation was missing, so to resolve this I've added It in gradle.build file. I thought Spring-boot already took care of It when getting JPA, but I was wrong. Here It is my updated dependencies from gradle.build:
dependencies {
//Spring
//implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
//runtimeOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
//Hibernate
implementation 'org.hibernate:hibernate-core:5.4.2.Final'
implementation 'org.hibernate:hibernate-entitymanager:5.4.2.Final'
//Postgres
implementation 'org.postgresql:postgresql:42.2.5.jre7'
//Gson
implementation 'com.google.code.gson:gson:2.8.5'
//Logger
implementation 'log4j:log4j:1.2.17'
}
try to add
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

Android project with Java and Kotlin files, kapt or annotationProcessor?

I would like to know if in an Android project mixing Java and Kotlin files we must use annotationProcessor or kapt, or both ?
In my understanding annotationProcessor must be used for Java files using annotations for code generation, and kapt must be used for Kotlin files using annotations for code generation.
I have a project mixing both languages, and I just have replaced all the annotationProcessor dependencies in the build.gradle by kapt.
Surprisingly it builds and seems to run correctly but I do not understand why kapt works well even with Java files...
Can someone explain to me ?
Thank you
First of all, the Kotlin Annotation processing tool (kapt) uses the Java compiler to run annotation processors. If your project contains any Java classes, kapt takes care of them by design. Kotlinlang recommends using kapt incase you used annotationProcessor from the Android Support before.
JetBrains has a nice article about how kapt works in more detail, its from 2015 but UP-TO-DATE.
In Java you can specify annotationProcessor (or apt) dependency like below:
dependencies {
...
annotationProcessor "com.google.dagger:dagger-compiler:$dagger-version"
}
In Kotlin you have to add the kotlin-kapt plugin to enable kapt, and then replace annotationProcessor with kapt:
apply plugin: 'kotlin-kapt' //Must include
dependencies {
...
kapt "com.google.dagger:dagger-compiler:$dagger-version"
}
That's all! Note that kapt takes care of your Java files as well as kotlin file, so you don't need to keep the annotationProcessor dependency.
For more details: link

Categories