use android gradle plugin 3.0.0 is slower than gradle plugin 2.3.3 - gradle

when update the com.android.tools.build:gradle:2.2.3 to com.android.tools.build:gradle:3.0.0 , and I find the build-time is longer than 2.3.3 .
the root build.gradle is
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
}
}
the app/build.gradle is here , and all my dependencies use compile
apply plugin: 'com.android.application'
android {
sourceSets {
main {
...
}
}
dexOptions {
preDexLibraries = false
incremental true
javaMaxHeapSize "8g"
keepRuntimeAnnotatedClasses false
}
lintOptions {
abortOnError false
checkReleaseBuilds false
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'org/apache/commons/codec/language/bm/*.txt'
}
compileSdkVersion 24
buildToolsVersion "27.0.1"
}
defaultConfig {
applicationId "com.gg.kk"
minSdkVersion 15
targetSdkVersion 23
versionCode 512654
versionName "version"
multiDexEnabled true
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:multidex:1.0.1'
.... many dependencies ....
}
can anyone tell me why my build become slow?

Many different things can effect gradle build times.
To decrease this time you may want to try at least one of this solutions:
Check if Gradle Deamon is enabled. It should be enabled by default.
Keep your Gradle up-to-date (You are already good at this though)
you can go /gradle/wrapper/gradle-wrapper.properties and upgrade gradle version by changing distributionUrl
Increase your heapsize
org.gradle.jvmargs=-Xmx3072m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
Enable parallelism in your gradle.properties by adding org.gradle.parallel=true
Don't use dynamic dependencies like compile 'com.android.support:appcompat-v7:27.+'
File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle
Check the 'Offline work' under 'Global Gradle settings' Short term solution.
Check this https://developer.android.com/studio/build/optimize-your-build.html

Related

Trying to add timber to Kotlin project results in multiple 'Unable to resolve dependency for...' Gradle errors

I have added implementation 'com.jakewharton.timber:timber:4.7.1' to my Kotlin project and now I get the following Gradle errors:
Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve com.jakewharton.timber:timber:4.7.1.
Open File
Show Details
Unable to resolve dependency for ':app#debugAndroidTest/compileClasspath': Could not resolve com.jakewharton.timber:timber:4.7.1.
Open File
Show Details
Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve com.jakewharton.timber:timber:4.7.1.
Open File
Show Details
Unable to resolve dependency for ':app#release/compileClasspath': Could not resolve com.jakewharton.timber:timber:4.7.1.
Open File
Show Details
Unable to resolve dependency for ':app#releaseUnitTest/compileClasspath': Could not resolve com.jakewharton.timber:timber:4.7.1.
Open File
Show Details
Strangely though I can see it downloading as Gradle syncs:
I also tried adding timberkt but got a similar error.
My whole app/build.gradle file looks like this:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlinx-serialization'
android {
compileSdkVersion 26
defaultConfig {
applicationId "uk.co.davechambers.pegboard"
targetSdkVersion 26
minSdkVersion 21
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary= true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
google()
jcenter()
maven { url "https://kotlin.bintray.com/kotlinx" }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.0.0-beta2'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:design:26.0.0-beta2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-vector-drawable:26.0.0-beta2'
implementation 'com.jakewharton.timber:timber:4.7.1'
compile "org.jetbrains.anko:anko:$anko_version"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"
}
kotlin {
experimental {
coroutines "enable"
}
}
androidExtensions {
experimental = true
}
Clearly I'm doing something wrong. Can anybody point me in the right direction?
I added an additional Maven url to build.gradle (Module: app):
repositories {
google()
jcenter()
maven { url "https://kotlin.bintray.com/kotlinx" }
maven { url "http://jcenter.bintray.com"}
}
and to build.gradle (Project: projectName):
buildscript {
ext.kotlin_version = '1.2.40'
ext.anko_version = '0.10.5'
ext.serialization_version = '0.4.1'
repositories {
google()
jcenter()
maven { url "https://kotlin.bintray.com/kotlinx" }
maven { url "http://jcenter.bintray.com"}
}
.....
After that, everything worked.

Too many classes in --main-dex-list, main dex capacity exceeded with javafxports-plugin

I am trying to make my application run on an android device by using the jfxmobile-plugin.
When I do a
gradle android
on my project I get
Execution failed for task ':dex'.
> UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Too many classes in --main-dex-list, main dex capacity exceeded
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:546)
at com.android.dx.command.dexer.Main.runMultiDex(Main.java:366)
at com.android.dx.command.dexer.Main.run(Main.java:275)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
My gradle file is this
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.2'
}
}
apply plugin: 'org.javafxports.jfxmobile'
mainClassName = 'de.package.of.application.ClientApp'
dependencies {
compile 'com.annimon:stream:1.0.1'
compile 'com.jakewharton.threetenabp:threetenabp:1.0.4'
compile 'com.gluonhq:charm:4.2.0'
androidRuntime 'com.gluonhq:charm-android:3.0.0'
iosRuntime 'com.gluonhq:charm-ios:3.0.0'
desktopRuntime 'com.gluonhq:charm-desktop:3.0.0'
compile fileTree(dir: 'target/dependencies', include: '*.jar')
runtime fileTree(dir: 'target/dependencies', include: '*.jar')
}
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
jfxmobile {
ios {
forceLinkClasses = ['ensemble.**.*']
}
android {
//manifest = 'AndroidManifest.xml'
compileSdkVersion = '24'
androidSdk='C:/Tools/android-sdk-windows'
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
//... some more excludes
}
dexOptions {
javaMaxHeapSize '3g'
// keepRuntimeAnnotatedClasses false
}
}
}
I found some similar questions about the exception logged by the gradle build but non brought a real solution for me so far especially in combination with the usage of the javafxports-plugin.
Some suggested to set the compileSdkVersion to a minumum of 21-> I
use 24 -> this does not help.
Using keepRuntimeAnnotatedClasses=false is not an option because the
application is build on some Reflection/injection-logic
(spring-framework).
As I understand the build process takes those classes into account to
put in the main-dex-file which are required to initially start up the
application. So I stripped down the application to an absolut minimum
with no other dependencies (direct or transitive) to the other
libraries of my application (no imports of classes from other
libraries, except to java/javafx). The other libraries are
included by the 'runtime fileTree...' part of the gradle-file but
are not really used at startup. Idea was to create a 2-phase
startup of the application: First a minimum-app and then, when
the minimum app is loaded, start the real application code. -> no
success, it seems all libraries are taken into account for the
main-dex-file.
I do not see how to solve it together with javafxports. Does anyone have suggestions?

how to add repositories and dependencies in Gradle for android . Actually am trying to integrating SDk in my existing app

Can Anyone explain me what is Version Tag for git in this, I am getting error while importing this.
apply plugin: 'com.android.application'
buildscript {
repositories {
maven { url 'https:example.com' }
jcenter()
mavenCentral()
mavenLocal()
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.jatinder.bdugame"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'org.bitbucket.5elements:SmartTones-SDK:VERSION_TAG'
}
Error:
Error:(45, 13) Failed to resolve: org.bitbucket.5elements:SmartTones-SDK:VERSION_TAG
Show in File<br>Show in Project Structure dialog
What does you question have to do with Git or Maven?
It does not even have anything to do with Android, besides coming from an Android project.
You declared the compile time dependency org.bitbucket.5elements:SmartTones-SDK:VERSION_TAG which means group org.bitbucket.5elements, artifact SmartTones-SDK, version VERSION_TAG. This combination is not found in any of your declared repositories, so it fails to be resolved, just as the error tells you.

Error : Gradle: Duplicate files during packaging of APK

In my gradle android application when I run the application I got below error.
Error:Gradle: duplicate files during packaging of APK /home/WorkSpace/MyProject/app/build/outputs/apk/app-debug-unaligned.apk
Error:Gradle: Execution failed for task ':app:packageDebug'.
Duplicate files copied in APK META-INF/license.txt
File 1: /home/.gradle/caches/modules-2/files-2.1/org.springframework.android/spring-android-rest-template/1.0.1.RELEASE/e132d929bd181941f79b0d63edafb8a86ae6fd33/spring-android-rest-template-1.0.1.RELEASE.jar
File 2: /home/.gradle/caches/modules-2/files-2.1/org.springframework.android/spring-android-core/1.0.1.RELEASE/e68f0e8e4b636ee30c4de58953be38d9b72a5e3b/spring-android-core-1.0.1.RELEASE.jar
Below is my gradle file.
build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
apply plugin: 'com.android.application'
repositories {
jcenter()
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.myproject.app"
minSdkVersion 9
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/notice.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:gridlayout-v7:23.2.0'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:support-v4:23.2.0'
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
compile 'org.apache.commons:commons-io:1.3.2'
compile 'joda-time:joda-time:2.3'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.2'
compile 'com.fasterxml.jackson.core:jackson-core:2.7.2'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.2'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.android.support:design:23.2.0'
}
How I can solve this error? Please help me.
Add below lines in the packagingOptions and dependencies.
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
And in dependencies use as below.
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:cardview-v7:23.2.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
compile('org.springframework.android:spring-android-auth:1.0.1.RELEASE') {
exclude module: 'spring-core'
}
compile 'org.springframework.android:spring-android-core:1.0.1.RELEASE'
compile 'org.apache.commons:commons-io:1.3.2'
compile 'joda-time:joda-time:2.3'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.2'
compile 'com.fasterxml.jackson.core:jackson-core:2.7.2'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.2'
compile 'com.google.code.gson:gson:2.6.2'
}
I think this will solve your issues.
You already have this in your build file:
packagingOptions {
exclude 'META-INF/notice.txt'
}
You can just add license.txt there as well.

Problen add dependency android studio

I posted my library in Artifactory
https://imagizer.imageshack.us/v2/806x253q90/631/kkK1Yn.png
this is my Gradle
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle',
version: '3.0.1')
}
}
repositories {
jcenter()
mavenCentral()
mavenLocal()
maven {
url 'http://myartifactory:8081/artifactory/gradle-local'
}
}
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'com.android.library'
apply plugin: 'android-apt'
def AAVersion = '3.2'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
}
}
dependencies {
compile fileTree(include: ['*.jar', '*.so'], dir: 'libs')
compile 'com.android.support:recyclerview-v7:21.0.+'
compile 'com.android.support:appcompat-v7:21.0.+'
compile 'com.android.support:support-v4:21.0.+'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.github.chrisbanes.photoview:library:1.2.3'
compile 'it.sephiroth.android.exif:library:+'
compile 'com.joanzapata.android:android-iconify:1.0.8'
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.afollestad:material-dialogs:0.6.0'
compile 'com.github.lzyzsd:circleprogress:1.0.1#aar'
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
compile(group: 'com.mylibrary.android.common', name: 'android.common', version: '1.0.0', ext: 'aar')
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName 'com.mypackage.library'
}
}
I get this error
https://imagizer.imageshack.us/v2/519x72q90/540/8ojerK.png
Gradle I found that running the route using the url wrong use "/" instead of "."
Try to find
...8081/artifactory/repo/com/mypackage/android/common/android.common/1.0.0/android.common-1.0.0.aar
but should be
...8081/artifactory/repo/com.mypackage.android.common/android.common/1.0.0/android.common-1.0.0.aar
I'm doing wrong, wrong as was published in the artefactory
Your artifact is not complaint to the standard Maven layout, in which the groupId should be separated by /, not by ..
It's not a big deal, Gradle can handle it easly, you just can't declare the repository as maven, but as ivy instead.
Actually, it will be easier to use the artifactory plugin for resolution, it also supports both Maven and Ivy layouts.
Also, please remember to set the repository in Artifactory to be with correct layout (not Maven2, probably Ivy).
And frankly, I think maybe it worth redeploying the artifact under Maven layout, it will make your life easier.

Resources