DuplicateFileException in apk build using Kotlin - java

I am trying to build a basic app using Kotlin/Anko but I am getting the following duplicate file exception
Execution failed for task
':app:transformResourcesWithMergeJavaResForDebug'.>
com.android.build.api.transform.TransformException:
com.android.builder.packaging.DuplicateFileException: Duplicate files
copied in APK kotlin/internal/internal.kotlin_builtins File1:
C:\Users\mahesh.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-runtime\1.0.6.\3562c66f648480d3bd4f76cff722488ced13445b\kotlin-runtime-1.0.6.jar File2:
C:\Users\mahesh.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-compiler-embeddable\1.0.6\4008eb91a337b377dae7e4572b8b543e5321f549\kotlin-compiler-embeddable-1.0.6.jar
Following is the code for the app level gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
buildscript {
ext.kotlin_version = '1.0.6'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
repositories {
jcenter()
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.kotlin.androdikotlinexample"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
//kotlin
compile "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
//anko
compile "org.jetbrains.anko:anko-design:0.8.3"
compile "org.jetbrains.anko:anko-support-v4:0.8.3"
compile "org.jetbrains.anko:anko-sdk15:0.8.3"
compile 'org.jetbrains.anko:anko-appcompat-v7:0.8.3'
}
Following is the code for Project level gradle file:
buildscript {
ext.kotlin_version = '1.0.6'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And this is the basic code for the MainUI file
class MainUI : AnkoComponent<MainActivityKotlin> {
override fun createView(ui: AnkoContext<MainActivityKotlin>): View = with(ui) {
coordinatorLayout {
verticalLayout {
// maybe put some content here
}
floatingActionButton {
imageResource = android.R.drawable.ic_menu_edit
onClick {
ui.owner.startActivityForResult<MainActivityKotlin>(1)
}
}.lparams {
gravity = Gravity.BOTTOM or Gravity.END
}
}
}
}
And the content is set on MainActivityKotlin file using the method MainUI().setContentView(this) in its onCreatemethod.
I have tried deleting the gradle cache and building the project again but nothing works. Please let me know where am I going wrong?

Remove compile "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" from your gradle
Remove also all buildscript section from you app level gradle

Try this one:
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile ("org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version") {
transitive = false
}
Also you don't need the android-extensions dependency anymore, as it's bundled into the plugin. Just having the apply plugin: 'kotlin-android-extensions' in your gradle is enough.

Related

How to convert all the contents of a .aar package to a .jar package?

I am trying to convert a .aar package to a .jar package according to the title above. I have tried several procedures(including those mentioned here), but all without success. It seems that it is necessary to convert all the contents of the package (including resources, manifest, etc.) to .jar.
The reason for this is that I need to publish .jar files together with my library in an artifactory repository, since .aar gets the following error when referencing it in 'libs /' in the assemble process:
Execution failed for task ':integration-lib:bundleReleaseAar'.
> Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR.
Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error). The following direct local .aar file dependencies of the :integration-lib project caused this error: /Users/thomas/Projetos/mobile-integration-lib/integration-lib/libs/PPCompAndroid-v1.32.aar
I also tried to import it by creating a new module with .jar/.aar file and referencing it in the library gradle, but it is not deployed in the artifactory repository.
My Gradle library:
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
def application = new Application()
class Application {
def packageName = 'com.soufan.integration-lib'
def versionMajor = 0
def versionMinor = 0
def versionPatch = 27
def versionName() {
return (versionPatch > 0 ? "${versionMajor}.${versionMinor}.${versionPatch}" : "${versionMajor}.${versionMinor}")
}
def static gitVersion() {
def process = ['/bin/bash', '-c', 'git rev-list HEAD | wc -l | xargs'].execute()
return process.text.toInteger()
}
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.0"
defaultConfig {
minSdkVersion 22
targetSdkVersion 30
versionCode application.gitVersion()
versionName application.versionName()
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
publishing {
publications {
aar(MavenPublication) {
groupId application.getPackageName()
version application.versionName()
artifactId project.getName()
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.compile.allDependencies.each { dependency ->
if (dependency.group != null) {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dependency.group)
dependencyNode.appendNode('artifactId', dependency.name)
dependencyNode.appendNode('version', dependency.version)
}
}
}
}
}
}
artifactory {
contextUrl = URL_DEPLOY
publish {
repository {
repoKey = DEPLOY_REPO_KEY
username = USER_NAME
password = API_KEY
}
defaults {
publications('aar')
publishArtifacts = true
properties = ['qa.level': 'basic', 'dev.team': 'core']
publishPom = true
}
}
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
implementation 'com.squareup.okhttp3:okhttp:4.0.1'
// Dependencies
implementation files('libs/NeptuneLiteApi_V2.04.00_20180329.jar')
implementation files('libs/PPCompAndroid-v1.32.aar')
implementation files('libs/libposdigital-1.5.1-4-release.aar')
implementation files('libs/zoop-emv-connect-pax-a920-pos_0.10.jar')
}
My Project Gradle:
buildscript {
ext.kotlin_version = "1.3.72"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.10.0"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

How Fix Package name 'android.support.graphics.drawable' used in: com.android.support:animated-vector-drawable:28.0.0

AndroidManifest.xml Error: Package name
'android.support.graphics.drawable' used in:
com.android.support:animated-vector-drawable:28.0.0,
com.android.support:support-vector-drawable:28.0.0
https://imgur.com/6aFUN59
https://imgur.com/C1EmnJ3
An error happened after upgrade Android Studio 3.4
Already try change compileSdk to 27 / 27.1.1 but still same
and already try to disable "vector-drawable" lib but still same
.
.
.
.
.
.
.
.
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url 'https://maven.fabric.io/public'}
maven { url 'https://maven.google.com' }
}
dependencies {
classpath 'com.google.gms:google-services:4.2.0'
classpath 'io.fabric.tools:gradle:1.26.1'
classpath 'com.google.firebase:firebase-plugins:1.2.0'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.google.firebase.firebase-perf'
android {
compileSdkVersion 28
defaultConfig {
applicationId "xxx.packacge.name"
minSdkVersion 21
targetSdkVersion 28
versionCode 4
versionName "Dev"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
applicationVariants.all { variant ->
//variant.getAssembleProvider()
variant.outputs.all {
outputFileName = "${variant.name}-${variant.versionName}.apk"
}
}
buildTypes {
release {
minifyEnabled false
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
}
}
buildToolsVersion = '28.0.3'
}
repositories {
mavenCentral()
jcenter()
maven { url 'https://maven.google.com' }
}
dependencies {
configurations.all {
exclude group: 'com.android.support', module: 'support-v13'
}
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-vector-drawable:28.0.0'
implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha5'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:support-fragment:28.0.0'
}
apply plugin: 'com.google.gms.google-services'
..
buildscript {
repositories {
google()
jcenter()
mavenCentral()
maven {
url 'https://maven.fabric.io/public'
}
maven {
url 'https://maven.google.com/'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.firebase:firebase-plugins:1.2.0'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
mavenCentral()
maven {
url 'https://maven.google.com/'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
..
You should try this way
implementation('com.android.support:support-vector-drawable:28.0.0') {
exclude group: 'android.support.graphics.drawable'
exclude module: 'support-vector-drawable'
}
implementation('com.android.support:support-vector-drawable:28.0.0') {
exclude group: 'android.support.graphics.drawable'
exclude module: 'support-vector-drawable'
}
try this one

Gradle sync failed: Plugin with id 'com.google.android.gms:play-services' not found

In one of my projects I need to use GoogleMaps and Firebase for notifications but the libraries of the service and the Firebase in place do not want to work.
buildscript {
repositories {
google()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.google.android.gms:play-services:8.4.0'
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
jcenter()
}
}
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url "https://maven.google.com" }
}
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.online.app"
minSdkVersion 16
targetSdkVersion 25
versionCode 8
versionName "2.5"
multiDexEnabled true
}
buildTypes {
release {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:26.0.2'
compile 'me.leolin:ShortcutBadger:1.1.6#aar'
compile('com.crashlytics.sdk.android:crashlytics:2.6.0#aar') {
transitive = true;
}
compile "com.google.firebase:firebase-ads:11.8.0"
compile "com.android.support:appcompat-v7:26.1.0"
compile 'com.android.support:multidex:1.0.1'
}
apply plugin: 'com.google.android.gms:play-services'
Error:
Gradle sync failed: Plugin with id 'com.google.android.gms:play-services' not found.
Consult IDE log for more details (Help | Show Log) (2s 325ms)
change this:
apply plugin: 'com.google.android.gms:play-services'
to this:
apply plugin: 'com.google.gms.google-services'
check this for more info: https://developers.google.com/android/guides/google-services-plugin
You need to use
apply plugin: 'com.google.gms.google-services'
You have 2 errors:
In your buildscript block use the right plugin:
dependencies {
classpath 'com.google.gms:google-services:3.1.1'
// ...
}
Instead of classpath 'com.google.android.gms:play-services:8.4.0'
Then at the bottom you have also to change the name of the plugin:
apply plugin: 'com.google.gms.google-services'
instead of:
apply plugin: 'com.google.android.gms:play-services'
Also don't use 2 buildscript blocks.
Just remove this block, and add the repository and the plugin in the previous block:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}

Shrink Debug Multi Dex Component; Cannot Read dir/allclasses.jar

I am developing an application which enabling Multidex in order to avoid 65k limit. I want to add an external library in Jar type (i.e. iPay Jar SDK). I've Synchronized the Gradle and succeed but I failed to run the project.
The error message shown like below
Error:Execution failed for task ':app:shrinkDebugMultiDexComponents'.
java.io.IOException: Can't read [/[dir]/app/build/intermediates/multi-dex/debug/allclasses.jar] (Can't process class [com/ipay/IpayAcitivity.class] (Unknown verification type [14] in stack map frame))
This is my Gradle Code
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = '3.2'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
repositories {
mavenCentral()
mavenLocal()
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName '[My Package]'
}
}
dependencies {
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
compile fileTree(dir: 'libs', include: ['*.jar'])
//Libs folder contains: org.apache.http.legacy.jar
//and ipay88_androidv7.jar
compile 'com.loopj.android:android-async-http:1.4.5'
compile 'com.github.rey5137:material:1.2.1'
compile 'com.jpardogo.materialtabstrip:library:1.0.9'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "[My Application Id]"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java', 'build/source/apt/debug']
resources.srcDirs = ['src/main/res']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
}
beta {
resources.srcDirs = ['app/src/beta/res']
res.srcDirs = ['app/src/beta/res']
}
}
signingConfigs {
release {
...
}
}
}
Before I added this type of external library (i.e. iPay Jar SDK), the application was running successfully. But the problem arised after I had added iPay Jar SDK (second Jar Library).
For further information, I had already followed this guide on https://developer.android.com/tools/building/multidex.html
But it didn't work my project.
What's your suggestion to fix this error ?
Try this:
public class MyApplication extends MultiDexApplication
{
#Override
protected void attachBaseContext(Context base)
{
super.attachBaseContext( base );
}
#Override
public void onCreate()
{
MultiDex.install(getTargetContext());
super.onCreate();
}
}
It seems your library is not compatible with Multidex. So you better update the library to the latest version(if an update is available). Or use only the required Google Play services API in your application and get rid off Multidex. Replace
compile 'com.google.android.gms:play-services:8.1.0' (the whole library)
this with something you use in your app like this
compile 'com.google.android.gms:play-services-ads:8.1.0' (library only for ads)
and remove this compile 'com.android.support:multidex:1.0.1'
You can find all the Google Play services API here https://developers.google.com/android/guides/setup#add_google_play_services_to_your_project

Error : app:dexDebug finished with non-zero exit value 1

Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_51\bin\java.exe'' finished with non-zero exit value 1
hello i get this error, which i have no idea how to fix.
these are my gradles:
app gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc2"
defaultConfig {
applicationId "com.example.daniel.testing6"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
//compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(path: ':backend', configuration: 'android-endpoints')
//configurations { all*.exclude group: 'com.android.support', module: 'support-v4' }
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:design:22.2.1'
}
backend gradle:
// If you would like more information on the gradle-appengine-plugin please refer to the github page
// https://github.com/GoogleCloudPlatform/gradle-appengine-plugin
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.18'
}
}
repositories {
jcenter();
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.18'
compile 'com.google.appengine:appengine-endpoints:1.9.18'
compile 'com.google.appengine:appengine-endpoints-deps:1.9.18'
compile 'javax.servlet:servlet-api:2.5'
compile 'com.googlecode.objectify:objectify:4.0b3'
compile 'com.ganyo:gcm-server:1.0.2'
}
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
endpoints {
getClientLibsOnBuild = true
getDiscoveryDocsOnBuild = true
}
}
project gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
does any one know how to fix it???

Categories

Resources