Lombok in java module contributing to method count in apk - java

I'm using Lombok in a pure-java module inside an Android Studio project. This is the build.gradle for the module:
apply plugin: 'java'
apply plugin: 'war'
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
providedCompile "org.projectlombok:lombok:1.12.6"
testCompile 'junit:junit:4.12'
testCompile 'org.assertj:assertj-core:1.7.0'
compile 'com.google.code.gson:gson:2.7'
}
However when I build my android module the resulting APK has these method counts from lombok, when it should have none.
lombok: 4099
bytecode: 85
core: 308
debug: 18
handlers: 8
runtimeDependencies: 15
delombok: 253
ant: 22
eclipse: 820
agent: 223
handlers: 387
experimental: 16
extern: 6
apachecommons: 1
java: 1
log4j: 2
slf4j: 2
installer: 286
eclipse: 109
javac: 970
apt: 132
handlers: 317
java6: 24
java7: 24
java8: 26
libs: 996
com: 61
zwitserloot: 61
cmdreader: 61
org: 935
objectweb: 935
asm: 935
commons: 405
signature: 41
tree: 199
patcher: 316
equinox: 18
inject: 7
scripts: 150
Is this something wrong w/ lombok, how I'm using providedCompile or something with the Android/Gradle build system?

You should use compileOnly instead.
Disclosure: I am a lombok developer and not a gradle expert.

Related

Update Gradle project libraries

I have added web dependency by editing build.gradle file and adding line below in my Spring Eclipse Java project.
dependencies {
...
implementation 'org.springframework.boot:spring-boot-starter-web'
...
}
But project complains The import org.springframework.web cannot be resolved. How to tell Spring Tool Suite 4 project update this library?
UPD
My whole build.gradle :
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
id 'war'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '15'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
UPD 2
I have another project that was generated with web module from very beginning. I looked in project properties in both of them and found that current project don't have Web App Libraries :
Current project:
Should I ask gradle somehow update Spring Tool Suite project with required library?
UPD 3 Project file structure:
drwxrwxr-x 8 a a 4096 Oct 4 07:39 .
drwxrwxr-x 6 a a 4096 Oct 4 08:27 ..
drwxrwxr-x 5 a a 4096 Oct 1 08:18 bin
drwxrwxr-x 9 a a 4096 Oct 4 07:39 build
-rw-r--r-- 1 a a 599 Oct 4 05:32 build.gradle
-rw-rw-r-- 1 a a 1102 Oct 1 08:18 .classpath
-rw-r--r-- 1 a a 397 Oct 1 07:54 .gitignore
drwxrwxr-x 7 a a 4096 Oct 1 07:56 .gradle
drwxrwxr-x 3 a a 4096 Oct 1 07:54 gradle
-rwxr-xr-x 1 a a 5766 Oct 1 07:54 gradlew
-rw-r--r-- 1 a a 2763 Oct 1 07:54 gradlew.bat
-rw-r--r-- 1 a a 590 Oct 1 07:54 HELP.md
-rw-rw-r-- 1 a a 741 Oct 1 08:18 .project
drwxrwxr-x 2 a a 4096 Oct 1 08:18 .settings
-rw-r--r-- 1 a a 26 Oct 1 07:54 settings.gradle
drwxrwxr-x 4 a a 4096 Oct 1 07:54 src
did you also add
repositories {
mavenCentral()
}
To your gradle build? The maven import needs to resolved from somewhere, maven central is a good place.
According to Spring you also need to use the spring plugin
plugins {
id 'org.springframework.boot' version '2.3.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
At the top of your build gradle

java.lang.NoClassDefFoundError: Failed resolution Failed resolution of: Lcom/google/android/gms/common/internal/zzab;

I am following a tutorial (link) to upload images to Firebase database but am getting the below error. I rechecked the gradle dependencies and also enabled multidex support but error still remains
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzab;
at com.google.firebase.storage.FirebaseStorage.getInstance(Unknown Source)
at com.paperwrrk.android.storageref.MainActivity.<init>(MainActivity.java:36)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2351)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2510)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:102)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.zzab" on path: DexPathList[[dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-tubesock-0.0.11_74622aa9da17bf60443b34c100000d076f6631ba-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-support-annotations-25.0.0_416ca7aea2b0e15fba678c97c0d71c330758ffee-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-jackson-databind-2.2.2_169f7b55dddecf9b169deccb0ac50ee124eda962-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-jackson-core-2.2.2_3ae6e87b0280ab52f712dfb927e3401fe25aa21c-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-jackson-annotations-2.2.2_dd21f43a23482b41eb5ed094fcce68c90eeb0ffd-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-internal_impl-25.0.0_e8156948d2eb9e5ed0b41cc1f9f830e7838bb3b5-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-internal_impl-25.0.0_9056040795c4cf170b00cbf021bf976514542498-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-internal_impl-25.0.0_79b2045e82b81d2f064515f884990a3d2a9f29af-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-internal_impl-25.0.0_2879b3ac18601405060244958a8db64bdb3655f9-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-internal_impl-25.0.0_1ce40cec84eadc9153f026cb869c8b1760c8461a-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-firebase-client-jvm-2.3.1_764f8006
Gradle.app
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "com.paperwrrk.android.storageref"
minSdkVersion 18
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.google.firebase:firebase-database:10.0.0'
testCompile 'junit:junit:4.12'
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.google.firebase:firebase-auth:9.2.1'
compile 'com.google.firebase:firebase-storage:9.2.1'
compile 'com.android.support:multidex:1.0.0'
}
apply plugin: 'com.google.gms.google-services'
Please tell what I'm doing wrong here!
now here is the problem, you are using different versions in dependencies of gradle
So change this
compile 'com.google.firebase:firebase-database:10.0.0'
testCompile 'junit:junit:4.12'
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.google.firebase:firebase-auth:9.2.1'
compile 'com.google.firebase:firebase-storage:9.2.1'
compile 'com.android.support:multidex:1.0.0'
to this
compile 'com.google.firebase:firebase-database:10.0.1'
testCompile 'junit:junit:4.12'
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.google.firebase:firebase-auth:10.0.1'
compile 'com.google.firebase:firebase-storage:10.0.1'
compile 'com.android.support:multidex:1.0.0'
one more thing is that now com.firebae:firebase-client-android is deprecated so you need to replace it with com.google.firebase:firebase-database:10.0.1 and here is the documentation for that https://firebase.google.com/support/guides/firebase-android
I have faced similar problem while implementing native ad and killed almost 4 hours...
At last i have figured out that there are different com.google.android.gms:play-services-ads version in different module('17.1.1' and '12.0.0').
After changing all version to 17.1.1 it solved my problem.
If you are seeking solution for react-native project, make sure there is same version used among different modules and replace "+" with some latest available version.
Most of the time the problem is in the gradle. I had a similar problem until I changed firebase-(storage/auth/database) build gradle for module app to be the same for e.g.
( com.google.firebase:firebase-storage:16.1.0,com.google.firebase:firebase-auth:16.1.0, com.google.firebase:firebase-database:16.1.0)

spring boot gradle app on ubuntu: unable to access jarfile

I have an existing Spring app that I want to convert to a Spring Boot app. So I have added th Application.java file in my java source directory and execute my gradlwe script as usual. However, when I run the build command, a get an error saying 'unable to access jarfile' - although I specify the jarfile name in my build script and on my command line. Below is the build.gradle file and the output. What is wrong here?
build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'idea'
apply plugin: 'spring-boot'
archivesBaseName = 'spring4'
version = '1'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web:1.3.3.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-data-jpa:1.3.3.RELEASE'
compile 'org.hibernate:hibernate-core:4.3.6.Final'
compile 'mysql:mysql-connector-java:5.1.31'
compile 'commons-dbcp:commons-dbcp:1.4'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat:1.3.3.RELEASE'
compile "ch.qos.logback:logback-classic:1.1.3"
compile "org.slf4j:log4j-over-slf4j:1.7.13"
// tag::jetty[]
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
compile("org.springframework.boot:spring-boot-starter-jetty")
// end::jetty[]
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
// end::actuator[]
testCompile("junit:junit")
}
jar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
configurations.all {
exclude group: "org.slf4j", module: "slf4j-log4j12"
exclude group: "log4j", module: "log4j"
}
sourceSets {
main {
resources {
srcDirs "src/main/resources"
}
}
}
output:
vagrant#vagrant:/vagrant/Spring4RESTAngularJS$ ./gradlew build && java -jar build/libs/gs-spring-boot-0.1.0.jar
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:findMainClass
:war
:bootRepackage
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
BUILD SUCCESSFUL
Total time: 11.772 secs
Error: Unable to access jarfile build/libs/gs-spring-boot-0.1.0.jar
vagrant#vagrant:/vagrant/Spring4RESTAngularJS$
check target directory:
vagrant#vagrant:/vagrant/Spring4RESTAngularJS$ ll build/libs/
total 53697
drwxrwxrwx 1 vagrant vagrant 0 Sep 15 11:25 ./
drwxrwxrwx 1 vagrant vagrant 4096 Sep 13 09:54 ../
-rwxrwxrwx 1 vagrant vagrant 30698749 Sep 15 11:25 spring4-1.war*
-rwxrwxrwx 1 vagrant vagrant 24281990 Sep 15 11:24 spring4-1.war.original*
vagrant#vagrant:/vagrant/Spring4RESTAngularJS$

Unable to use the apache.poi library after adding gradle dependency

I've been trying to use the apache.poi library to create an excel file but, for some reason, I'm unable to import anything.
mainClassName = 'Main'
sourceCompatibility = 1.7
targetCompatibility = 1.7
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.api-client:google-api-client:1.22.0'
compile 'com.google.oauth-client:google-oauth-client-jetty:1.22.0'
compile 'com.google.apis:google-api-services-sheets:v4-rev21-1.22.0'
compile 'org.apache.poi:poi:3.9'
}
When I am trying to write import org.apache.poi; it gives me an error saying "Package does not exist".
What is wrong with my dependencies? Thanks.
Some times it is useful to reload a gradle project so gradle could download the binary of the new dependency. After that the new packages should be available.
Found the same error while including gradle in the build.gradle file.
Use:
compile group: 'org.apache.poi', name: 'poi', version: '3.9'
Like: dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile group: 'org.apache.poi', name: 'poi', version: '3.9'
compile 'com.android.support:appcompat-v7:23.4.0'
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "fl.gauravsngarg.com.inventory"
minSdkVersion 23
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile group: 'org.apache.poi', name: 'poi', version: '3.9'
compile 'com.android.support:appcompat-v7:23.4.0'
}
After research I found the actual version.
Use
// https://mvnrepository.com/artifact/org.apache.poi/poi
compile group: 'org.apache.poi', name: 'poi', version: '3.9'
Its given here
https://mvnrepository.com/artifact/org.apache.poi/poi/3.9
The site contains all the official dependencies for gradle, maven, etc.
It worked for me:
It is quite possible that you have enabled gradle sync in offline mode.
Just change that.
Works like a charm
I had the same issue!
For me File > Invalidate Chaches / Restart > Invalidate and Restart worked.
I am using this version: https://mvnrepository.com/artifact/org.apache.poi/poi/4.1.2
Worked for me:
compile group: 'org.apache.poi', name: 'poi-ooxml', version: '4.0.0'

UNEXPECTED TOP_LEVEL EXCEPTION Multiple dex files define Landroid/support/annotation/AnimRes

After I've added the new library to my project, I started to get this error:
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
D:\Android\sdk\build-tools\21.1.2\dx.bat --dex --no-optimize --output D:\Android\AndroidStudioProjects\Discounty\app\build\intermediates\dex\debug --input-list=D:\Android\AndroidStudioProjects\Discounty\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
I've looked through loads of similar questions on stackoverflow but didn't find the working solution.
Below's the screenshot of my project stucture and the build.gradle file of the library project (in libs folder), here's the link for the screenshot:
And here's my root build.gradle file:
buildscript {
repositories {
jcenter()
maven {
url "https://jitpack.io"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://jitpack.io"
}
}
}
And here's the build.grandle from the app folder:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.discounty.discounty"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'cn.pedant.sweetalert:library:1.3'
compile 'com.android.support:recyclerview-v7:21.0.0'
compile 'com.getbase:floatingactionbutton:1.6.0'
compile 'com.yalantis:contextmenu:1.0.0'
compile('de.keyboardsurfer.android.widget:crouton:1.8.4#aar') {
exclude group: 'com.google.android', module: 'support-v4'
}
compile project('libs:swipe_menu_list_view')
}
I tried cleaning the project, but it didn't help.
The new library that I've added (swipe_menu_list_view) contains the support-v4 dependency and I don't use support-v4 anywhere else in my project (or at least I think so), but I've read that this error might happen because different versions of the same library are used in one project.
Could you please help me with solving that problem?
It happens when you are using 2 different versions of the same library.
You can render the dependency tree with the command gradle dependencies
In your case:
'com.getbase:floatingactionbutton:1.6.0' uses
<dependency>
<groupId>com.android.support</groupId>
<artifactId>support-annotations</artifactId>
<version>19.1.0</version>
</dependency>
while you appcompat 21.0.3 uses
<dependency>
<groupId>com.android.support</groupId>
<artifactId>support-annotations</artifactId>
<version>21.0.3</version>
<scope>compile</scope>
</dependency>
You can check if there is a updated version that uses the same 21.0.3 or you can exclude the dependency with:
compile('com.getbase:floatingactionbutton:1.6.0') {
exclude group: 'com.android.support', module: 'support-annotations'
}

Categories