Duplicate class definitions in gradle assemble AAR library - android

I am compiling my AAR library in Android Studio, in the perfect debug mode, but when the release with ProGuard, the error occurs:
My build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.google.gms:google-services:3.2.0'
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 23
targetSdkVersion 28
multiDexEnabled true
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
version '3.10.2'
path "src/main/cpp/CMakeLists.txt"
}
}
repositories{
flatDir{
dirs 'libs'
}
/** Following lines are for accessing the TapLinx jars from Repo directly */
maven {
credentials {
username "sdkuser"
password "taplinx"
}
url "http://maven.taplinx.nxp.com/nexus/content/repositories/taplinx/"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.4.0-b180830.0359'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.9'
implementation 'com.google.android.gms:play-services-analytics:15.0.2'
implementation 'com.google.firebase:firebase-core:15.0.2'
implementation 'com.google.firebase:firebase-messaging:15.0.2'
implementation('taplinx-android:nxpnfcandroidlib:1.6#aar') {
transitive = true
changing = true
}
}
My Error Log is:
...
Reading library jar [/Users/andresflorespolicarpo/Library/Android/sdk/platforms/android-28/android.jar]
Reading library jar [/Users/andresflorespolicarpo/Library/Android/sdk/platforms/android-28/optional/org.apache.http.legacy.jar]
Reading library jar [/Users/andresflorespolicarpo/Library/Android/sdk/platforms/android-28/optional/android.test.mock.jar]
Reading library jar [/Users/andresflorespolicarpo/Library/Android/sdk/platforms/android-28/optional/android.test.base.jar]
Reading library jar [/Users/andresflorespolicarpo/Library/Android/sdk/platforms/android-28/optional/android.test.runner.jar]
Note: there were 1 duplicate class definitions.
(http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)
Warning: there were 1 classes in incorrectly named files.
You should make sure all file names correspond to their class names.
The directory hierarchies must correspond to the package hierarchies.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unexpectedclass)
If you don't mind the mentioned classes not being written out,
you could try your luck using the '-ignorewarnings' option.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':taplinx:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: Please correct the above warnings first.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 3s
40 actionable tasks: 32 executed, 8 up-to-date
12:56:13: Task execution finished 'assemble'.

This is a bug with Taplinx version solves in 1.7

Related

Problems with android Compose

I am trying to work through a tutorial on android compose. It works well while I use:kotlin-gradle-plugin:1.5.31, but the android studio has updated to :kotlin-gradle-plugin:1.6.10, and when I try running the program again it doesn't compile. I don't understand what the problem is. but even in the original run with the old version, I get the following message:
w: ATTENTION!
This build uses unsafe internal compiler arguments:
-XXLanguage:+NonParenthesizedAnnotationsOnFunctionalTypes
This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!
when I try the new version it tells me that I must migrate the code, but when I do this I get the following message:
e: This version (1.0.5) of the Compose Compiler requires Kotlin version 1.5.31 but you appear to be using Kotlin version 1.6.10 which is not known to be compatible. Please fix your configuration (or suppressKotlinVersionCompatibilityCheck but don't say I didn't warn you!).
Task :app:mergeExtDexDebug
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
Compilation error. See log for more details
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 10s
25 actionable tasks: 23 executed, 2 up-to-date
and you can't migrate back even if you want to.
I don't know what to do with this or how to proceed forward.
I managed to find out that the right compos version for kotlin 1.6.10 is 1.2.0-alpha01, but I still get the message that this is not a stable version and should not be production use. But at least my program runs again.
Finally, Figure out and fix the issue to run compose version
Currently Stable version 1.1.0
So here is my code for build.gradle(Project:app)
buildscript {
ext {
compose_version = '1.1.0'
}
dependencies {
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.1' apply false
id 'com.android.library' version '7.1.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(Module)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.dreammeanings"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
implementation 'androidx.activity:activity-compose:1.4.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
}
In my case i specified kotlinCompilerExtensionVersion for composeOptions in build.gradle of the app module and error fixed:
build.gradle(app)
android {
composeOptions { kotlinCompilerExtensionVersion = "your compose version"}
}
I think your problem is with the version of Compose and Kotlin.
A few days ago, I encountered a similar error, and after updating the Kotlin and Compose versions, my problem was fixed.
First of all change composeOptions:
composeOptions {
kotlinCompilerExtensionVersion compose_version
//kotlinCompilerVersion '1.5.31' the old version
kotlinCompilerVersion '1.6.21'
}
then update all your dependencies versions
dependencies {
implementation "androidx.compose.ui:ui-tooling:$compose_version"
.
.
.
}
then add this classpaths to gradle dependencies
dependencies {
//the older version of kotlin
//classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"
.
.
.
}
At the end, i think this is an version compatibility issue between Kotlin and compose libraries.
You just need to update your dependencies.
Note : the $compose_version that i used in the dependencies is an variable in buildscript
buildscript {
ext {
kotlin_version = "1.6.21"
//compose_version = '1.0.5'
compose_version = '1.2.0-rc01'
}
.
.
.
}
I hope it helps you to solve your problem.

How to fix NDK build error for HelloCardboard sample

I am trying to compile Google Cardboard Sdk sample.
I am following instructions given by google's official docs
I am stuck at step 3, where I am supposed to assemble the project:
This is the error I am getting when I start to assemble:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':hellocardboard-android:externalNativeBuildDebug'.
> Build command failed.
Error while executing process C:\Users\Shanu\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C C:\Projects\cardboard\hellocardboard-android\.cxx\cmake\debug\x86 cardboard_jni}
ninja: Entering directory `C:\Projects\cardboard\hellocardboard-android\.cxx\cmake\debug\x86'
ninja: error: '../../../../libraries/jni/x86/libcardboard_api.so', needed by '../../../../build/intermediates/cmake/debug/obj/x86/libcardboard_jni.so', missing and no known rule to make it
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 4s
29 actionable tasks: 2 executed, 27 up-to-date
1:55:12 PM: Task execution finished 'assemble'.
Then I tried to run with --stacktrace
Caused by: org.gradle.internal.UncheckedException: Build command failed.
But there is an additional warning:
WARNING: This app only has 32-bit [armeabi-v7a,x86] native libraries. Beginning August 1, 2019 Google Play store requires that all apps that include native libraries must provide 64-bit versions. For more information, visit https://g.co/64-bit-requirement
Well, that doesn't give me an idea, as to have never used NDK/Cardboard SDK ever before.
Here is how the build.gradle(hellocardboard) looks like:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.google.cardboard.hellocardboard"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk {
abiFilters 'armeabi-v7a', 'x86'
}
externalNativeBuild {
cmake {
cppFlags "-std=gnu++11"
arguments "-DANDROID_STL=c++_shared"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
// Android Mobile Vision
implementation 'com.google.android.gms:play-services-vision:15.0.2'
//noinspection GradleCompatible
implementation 'com.android.support:design:28.0.0'
implementation project(":sdk")
}
// The dependencies for NDK builds live inside the .aar files so they need to
// be extracted before NDK targets can link against.
task extractNdk(type: Copy) {
if (file("${project.rootDir}/sdk/build/outputs/aar/sdk-release.aar").exists()) {
copy {
from zipTree("${project.rootDir}/sdk/build/outputs/aar/sdk-release.aar")
into "libraries/"
include "jni/**/libcardboard_api.so"
}
copy {
from "${project.rootDir}/sdk/include/cardboard.h"
into "libraries/"
}
}
}
task deleteNdk(type: Delete) {
delete "libraries/jni"
delete "libraries/cardboard.h"
}
build.dependsOn(extractNdk)
clean.dependsOn(deleteNdk)
Here is the whole project hosted on my GitHub
Everything is at google's default settings, and I haven't configured anything, except
Install these components from the SDK manager:
CMake
LLDB
NDK (Side by Side)
What is the issue here and how can I fix it?
This usually happens when you haven't built the SDK.
The sample app tells you to click the "assemble" option in the Gradle tab. You should click the "assemble" option under ":sdk", not the one under ":hellocardboard-android".
The official instructions are unclear about this; it is only visible if you look closely at the screenshots there.

How to specify gradle version for subprojects or app level build.gradle

I have an Android (Kotlin) project that I want to test with spotbugs.
This testing will occur inside a docker container using the gitlab/sast image. It will detect a gradle project and then execute spotbugs tests on that project.
When I run this image with
docker run \
--interactive --tty --rm \
--volume ${MY_PROJECT}:/code \
--volume /var/run/docker.sock:/var/run/docker.sock \
registry.gitlab.com/gitlab-org/security-products/sast:12-4-stable /app/bin/run /code
The sast tool detects two projects in total, Gradlew and Gradle projects as showing in the logs.
Found Gradlew project in /tmp/app directory
Found Gradle project in /tmp/app/app directory
Found 2 analyzable projects.
The Gradlew is successfully built but the Gradle project fails to build.
Gradlew Plugin
Building Gradlew project at /tmp/app.
Downloading https://services.gradle.org/distributions/gradle-5.6.1-all.zip
Unzipping /root/.gradle/wrapper/dists/gradle-5.6.1-all/805usxkvhgx6e1wbo8o64g0tx/gradle-5.6.1-all.zip to /root/.gradle/wrapper/dists/gradle-5.6.1-all/805usxkvhgx6e1wbo8o64g0tx
Set executable permissions for: /root/.gradle/wrapper/dists/gradle-5.6.1-all/805usxkvhgx6e1wbo8o64g0tx/gradle-5.6.1/bin/gradle
Welcome to Gradle 5.6.1!
Here are the highlights of this release:
- Incremental Groovy compilation
- Groovy compile avoidance
- Test fixtures for Java projects
- Manage plugin versions via settings script
For more details see https://docs.gradle.org/5.6.1/release-notes.html
Starting a Gradle Daemon (subsequent builds will be faster)
> Task :app:assemble UP-TO-DATE
> Task :app:lint SKIPPED
> Task :app:compileJava NO-SOURCE
> Task :app:processResources NO-SOURCE
> Task :app:classes UP-TO-DATE
> Task :app:spotbugsMain
Warning at xsl:variable on line 348 column 57 of default.xsl:
SXWN9001: A variable with no following sibling instructions has no effect
Warning at xsl:variable on line 351 column 57 of default.xsl:
SXWN9001: A variable with no following sibling instructions has no effect
> Task :app:check
> Task :app:build
BUILD SUCCESSFUL in 1m 49s
1 actionable task: 1 executed
Project built.
Gradle Plugin
Building Gradle project at /tmp/app/app.
Welcome to Gradle 5.1!
Here are the highlights of this release:
- Control which dependencies can be retrieved from which repositories
- Production-ready configuration avoidance APIs
For more details see https://docs.gradle.org/5.1/release-notes.html
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
* Where:
Build file '/tmp/app/app/build.gradle' line: 6
* What went wrong:
An exception occurred applying plugin request [id: 'com.github.triplet.play', version: '2.5.0']
> Failed to apply plugin [id 'com.github.triplet.play']
> Gradle Play Publisher's minimum Gradle version is at least Gradle 5.6.1 and yours is Gradle 5.1. Find the latest version at https://github.com/gradle/gradle/releases, then run './gradlew wrapper --gradle-version=$LATEST --distribution-type=ALL'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 38s
Error: Project couldn't be built: exit status 1
2019/11/18 21:49:23 exit status 1
2019/11/18 21:49:23 Container exited with non zero status code
Just to provide some background on the com.github.triplet.play tool, it's a gradle plugin that is used to publish apk's to the Play Store.
I was not expecting the Gradle project to use version 5.1 because the Gradlew project used version 5.6.1 and in gradle/wrapper/gradle-wrapper.properties (project-level) I have specified version 5.6.1.
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-all.zip
build.gradle (project-level)
buildscript {
ext.kotlinVersion = '1.3.50'
ext.espressoVersion = "3.2.0"
ext.ktlintVersion = "9.1.0"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
allprojects {
apply from: "$rootDir/ktlint.gradle"
repositories {
google()
jcenter()
}
}
build.gradle (app-level)
plugins {
id 'com.github.triplet.play' version '2.5.0'
id "com.github.spotbugs" version "2.0.1"
id "com.github.hierynomus.license-report" version"0.15.0"
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "com.github.spotbugs"
android {
compileSdkVersion 29
defaultConfig {
applicationId "<REDACTED>"
minSdkVersion 21
targetSdkVersion 29
versionCode Integer.valueOf(System.env.VERSION_CODE ?: 1)
versionName "${System.getenv('APPLICATION_VERSION')}-${System.getenv('APPLICATION_BUILD_STAGE')}-${System.env.VERSION_SHA}"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
storeFile file("${System.getenv('KEYSTORE_FILE_PATH')}")
storePassword "${System.getenv('SIGNING_KEY_PASSWORD')}"
keyAlias "${System.getenv('SIGNING_KEY_ALIAS')}"
keyPassword "${System.getenv('SIGNING_KEY_PASSWORD')}"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
tasks.lint.enabled = false
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "androidx.test.espresso:espresso-idling-resource:$espressoVersion"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.7.1'
}
play {
serviceAccountCredentials = file("${System.getenv('PLAY_STORE_JSON_CONFIG_PATH')}")
releaseStatus = "${System.getenv('PLAY_RELEASE_STATUS')}"
}
spotbugs {
toolVersion = '4.0.0-beta4'
excludeFilter = file("$rootProject.projectDir/spotbugs/excludeFilter.xml")
reportsDir = file("$project.buildDir/spotbugsReports")
}
tasks.withType(com.github.spotbugs.SpotBugsTask) {
classes = files("$project.buildDir/intermediates/javac")
source = fileTree("app/src/main/java")
reports {
html.enabled = true
xml.enabled = false
}
}
sourceSets {
// we define `main` sourceSet here, so SpotBugs Gradle Plugin generates `spotbugsMain` task
main {
java.srcDirs = []
}
}
downloadLicenses {
dependencyConfiguration "compile"
}
Is there anyway in Gradle to configure the tmp/app/app (Gradle project) to use version 5.6.1 instead of version 5.1

Define Checkstyle Task with android gradle plugin 3.4.0

I upgraded my build.gradle file to android gradle plugin 3.4.0 with gradle 5.11.
My build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'checkstyle'
android {
compileSdkVersion 28
buildToolsVersion buildVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "myapp"
minSdkVersion 21
targetSdkVersion 28
versionName "5.20.0"
versionCode 520
}
dataBinding {
enabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation "com.android.support:support-v4:$supportLibVersion"
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
task checkstyle(type: Checkstyle) {
source 'src/'
include '**/*.java'
exclude '**/gen/**'
classpath = files()
reports {
xml {
destination "build/outputs/reports/checkstyle-results.xml"
}
}
group = JavaBasePlugin.VERIFICATION_GROUP
description = 'Performs checkstyle verification on the code.'
}
task checkstyleReport(dependsOn: 'checkstyle', group: JavaBasePlugin.VERIFICATION_GROUP) {
if (file("build/outputs/reports/checkstyle-results.xml").exists()) {
ant.xslt(in: "build/outputs/reports/checkstyle-results.xml",
style: "./config/checkstyle/checkstyle.xsl",
out: "build/outputs/reports/checkstyle-results.html"
)
}
}
When syncing I get the following error message:
FAILURE: Build failed with an exception.
Where: Build file '/Users/cs/Development/project/app/build.gradle'
What went wrong: A problem occurred evaluating project ':app'.
Could not find method destination() for arguments [build/outputs/reports/checkstyle-results.xml] on Report xml of type
org.gradle.api.reporting.internal.TaskGeneratedSingleFileReport.
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 1s ERROR: Gradle DSL method not found: 'destination()'
Possible causes: The project 'project' may be using
a version of the Android Gradle plug-in that does not contain the
method (e.g. 'testCompile' was added in 1.1.0). Upgrade plugin to
version 3.4.0 and sync project
The project 'project' may be using a version of
Gradle that does not contain the method. Open Gradle wrapper file
The build file may be missing a Gradle plugin. Apply Gradle plugin
The error points to this lines:
reports {
xml {
destination "build/outputs/reports/checkstyle-results.xml"
}
}
Has the syntax for destination been changed in gradle?
Solution
reports {
xml {
destination file("build/outputs/reports/checkstyle-results.xml")
}
}
The method used to take an Object, but now requires a File type as a parameter - hence the parameter error.
So passing in a file instead solves the problem.
You can see the expected parameter types here:
https://docs.gradle.org/current/javadoc/org/gradle/api/reporting/ConfigurableReport.html#setDestination-java.io.File-

Convert project from Android Studio version 2 to 3- problem with configuration

I have problem with configuration of android project. I upgraded Android Studio [AS] from v2 to v3 and got many problems. I changed gradle as is in documentation:
gradle-wrapper, gradle plugin version, repositories google or jcenter instead of maven. Please look at configuration:
I have project called mytwayapp which have build.gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
//{ url "http://jcenter.bintray.com/" }
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
dependencies {
implementation project(':app')
}
Next I have module called app with build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '27.0.3'
// buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.mytway.activity.registerformactivity"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
preDexLibraries = false;
javaMaxHeapSize "2g"
}
sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/res/assets/fonts'] } }
testOptions {
unitTests.returnDefaultValues = true
}
lintOptions {
abortOnError false
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.android.gms:play-services:8.4.0'
implementation 'com.android.support:appcompat-v7:23.1.1'
implementation 'com.android.support:support-v4:23.1.1'
implementation 'com.android.support:support-v13:23.1.1'
implementation 'joda-time:joda-time:2.9.4'
implementation files('../libs/MPAndroidChart-v3.0.1.jar')
//to remove when Dex is over memory
testImplementation group: 'org.powermock', name: 'powermock-api-easymock', version: '1.6.6'
testImplementation 'org.powermock:powermock-mockito-release-full:1.5.4'
testImplementation 'org.powermock:powermock-api-mockito:1.6.6'
testImplementation 'org.powermock:powermock-module-junit4:1.5.1'
testImplementation 'org.mockito:mockito-all:1.9.5'
testImplementation 'org.powermock:powermock-mockito-release-full:1.6.1'
testImplementation 'org.easymock:easymock:3.1'
// testCompile files('build/lib/powermock-easymock-1.6.6-full.jar')
testImplementation 'junit:junit:4.12'
}
Next is gradle-wrapper:
#Thu Mar 16 20:14:22 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
Problem:
I cannot sync with gradle,If I try then error:
Could not initialize class com.android.tools.idea.gradle.eclipse.GradleImport
When I try install from cmd, then:
./gradlew install -x test
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\android\BitBucket\mytwayapp\build.gradle' line: 22
* What went wrong:
A problem occurred evaluating root project 'mytwayapp'.
> Could not find method implementation() for arguments [project ':app'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
It means that problem is with main build.gradle with dependencies to ":app" but it looks good.
I tried refreshed, rebuild, invalidate, restarted and still have a problem.
Project structure looks strange here is a screen:
ANSWER:
Tips from below are not worked, I downgrade Android Studio from 3.4 to 3.1 and after some cosmetics change it compile. Thanks for your time.
Try to update to latest versions:
dependencies {
classpath 'com.android.tools.build:gradle:x.x.x'
}
And buildToolsVersion in build.gradle
Try change de compileSDkVersion and targetSdkVersion with the same number prefix of buildToolsVersion in app gradle file, like this:
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
// buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.mytway.activity.registerformactivity"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
}

Categories

Resources