Gradle issues with android support compilation in Unity export - unity3d

I have a multidex issue while compiling my project in Unity so I exported the project and imported it to gradle. I've fixed most dependencies but I cannot get rid of the following problem:
FAILURE: Build failed with an exception.
12:05:17.012 [ERROR] [org.gradle.BuildExceptionReporter]
12:05:17.012 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
12:05:17.012 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':mainProj:transformClassesWithJarMergingForRelease'.
12:05:17.012 [ERROR] [org.gradle.BuildExceptionReporter] > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/compat/BuildConfig.class
12:05:17.012 [ERROR] [org.gradle.BuildExceptionReporter]
and that goes to all support* projects. I had similar issues with other sdks but I fixed them by deleting the BuildConfig.class from their classes.jar files. For some reason, when I delete this class for the supportcompat2500 project (in this specific example) it keeps coming back - and I don't know where from.
my settings.gradle is:
include ':amazonAppStore'
include ':appLovin'
include ':chartboost'
include ':googleAIDL'
include ':googlePlay'
include ':heyzap'
include ':oneSignalConfig'
include ':samsungApps'
include ':shortcutBadger115'
include ':unityAds'
include ':vungle'
include ':animatedvectordrawable2500'
include ':cardviewv72340'
include ':common'
include ':customtabs2340'
include ':facebookandroidsdk4170'
include ':facebookandroidwrapper790'
include ':onesignalunity'
include ':playservicesads980'
include ':playservicesadslite980'
include ':playservicesbase980'
include ':playservicesclearcut980'
include ':playservicesgass980'
include ':playservicesgcm980'
include ':playservicesiid980'
include ':playserviceslocation980'
include ':playservicestasks980'
include ':supportcompat2500'
include ':supportcoreui2500'
include ':supportcoreutils2500'
include ':supportfragment2500'
include ':supportmediacompat2500'
include ':supportv42500'
include ':supportvectordrawable2500'
include ':mainProj'
mainProj.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "com.mainProj.mainProj"
minSdkVersion 15
targetSdkVersion 24
// Enabling multidex support.
multiDexEnabled true
}
lintOptions {
quiet true
abortOnError false
ignoreWarnings true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java.com.mainProj.mainProj']
resources.srcDirs = ['src/main/res']
renderscript.srcDirs = ['src']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets.bin.Data']
jniLibs.srcDirs = ['src/main/jniLibs']
}
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
dependencies {
compile 'com.android.support:multidex:1+'
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':amazonAppStore')
compile project(':appLovin')
compile project(':chartboost')
compile project(':googleAIDL')
compile project(':googlePlay')
compile project(':cardviewv72340')
compile project(':customtabs2340')
compile project(':heyzap')
compile project(':oneSignalConfig')
compile project(':samsungApps')
compile project(':shortcutBadger115')
compile project(':unityAds')
compile project(':vungle')
compile project(':common')
compile project(':facebookandroidsdk4170')
compile project(':facebookandroidwrapper790')
compile project(':onesignalunity')
compile project(':playservicesads980')
compile project(':playservicesadslite980')
compile project(':playservicesbase980')
compile project(':playservicesclearcut980')
compile project(':playservicesgass980')
compile project(':playservicesgcm980')
compile project(':playservicesiid980')
compile project(':playserviceslocation980')
compile project(':playservicestasks980')
compile project(':supportcompat2500')
compile project(':supportcoreui2500')
compile project(':supportcoreutils2500')
compile project(':supportfragment2500')
compile project(':supportmediacompat2500')
compile project(':supportv42500')
compile project(':supportvectordrawable2500')
}
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:2.2.3'
}
}
allprojects {
repositories {
jcenter()
}
}
Would appreciate any advice/referenece. Thanks.

The problem was that
facebookandroidwrapper790
already include com.android.support and all of its sub-projects.
I've removed all
compile project(':support*')

Related

Unity 2020.2.6 Android build aptOptions noCompress property definition error

today I tried to build my game for Android with Unity 2020.2.6f1 and it gave the error below;
UnityException: Error mainTemplate.gradle file is using the old
aaptOptions noCompress property definition which does not include
types defined by unityStreamingAssets constant.
I disabled the Android Resolvers Patch gradle and manifest files it didn't work.
I tried to edit the gradle manually with;
aaptOptions {
noCompress = ['.ress', '.resource', '.obb'] + unityStreamingAssets.tokenize(', ')
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
}
whatever I do when building the game Unity overrides the gradle, I checked the pre-post build process scripts in the project but none of the ones I check changes the gradle' aaptOptions.
The plugins I have in the project are;
Facebook
GameAnalytics
Adjust
mainTemplate.gradle:
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
}
}
allprojects {
repositories {
google()
jcenter()
flatDir {
dirs 'libs'
}
}
}
apply plugin: 'com.android.library'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.installreferrer:installreferrer:1.0'
**DEPS**
}
android {
compileSdkVersion **APIVERSION**
buildToolsVersion '**BUILDTOOLS**'
defaultConfig {
multiDexEnabled true
minSdkVersion 19
targetSdkVersion 29
versionCode **VERSIONCODE**
versionName '**VERSIONNAME**'
}
dexOptions {
preDexLibraries false
javaMaxHeapSize "4g"
}
lintOptions {
abortOnError false
}
packagingOptions {
exclude 'jsr305_annotations/Jsr305_annotations.gwt.xml'
}
aaptOptions {
noCompress '.unity3d', '.ress', '.resource', '.obb'**STREAMING_ASSETS**
}
**SIGN**
buildTypes {
debug {
jniDebuggable true
}
release {
minifyEnabled false
**SIGNCONFIG**
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_8
}
}
Thanks in advance.
you should modify like this in the mainTemplate.gradle file :
aaptOptions {
noCompress = ['.ress', '.resource', '.obb'] + unityStreamingAssets.tokenize(', ')
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
}
For me what worked was unchecking the "Custom Gradle Template" option for the build inside Player Settings > Publishing Settings.
Edit: Okay it turns out that I can't replicate that anymore and I am not really sure what kind of wizardry allowed it to happen...
On the other hand, I found what caused the issue for me.
The problem was caused by one plugin I was using, since I was importing an old version of it and for some reason it kept importing gradle documents and other Android related stuff, which were deprecated.
I fixed it by importing everything from the plugin's Unity Package except the Android folder, all the Editor's gradles and gradle related stuff (I didn't import the Editor folder at all) and the Plugins folder.
Let's try this option. Work like champ.
Open file maingradle in Android folder and remove line have string "Proguard" then save file
Go to project setting => untick mainGradle and tick again mainGradle, untick gradle properties template and tick it again. Go to Asset option in top => find option force resolve and rebuild again.

gradle scalatest stay at "Discovery starting."

I have project that uses gradle, scala, scalatest and the gradle-scalatest-plugin.
I have several tests and they are compiled. But when the run part of them is executed, the gradle is stuck on "Dicovery starting." infinitely.
So I used gradle --debug test to see what is happening. But besides the status information about memory of jvm and lock acquiring, there is no information why it is stuck.
build.gradle File:
buildscript {
ext.scala_version = "2.12"
ext.akka_version = "2.5"
ext.monocle_version = "1.5.0"
ext.circe_version = "0.8+"
repositories {
mavenCentral()
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.diffplug.gradle:goomph:3.9.0"
}
}
plugins {
id "java"
id "scala"
id "com.github.maiflai.scalatest" version "0.19"
id "com.athaydes.osgi-run" version "1.5.4"
id "org.dm.bundle" version "0.10.0"
// For interoperability with Other Company Eclipse P2 Repository
id "com.diffplug.gradle.p2.asmaven" version "3.9.0"
}
group "project.scalatest"
version 0.1
repositories {
mavenCentral()
jcenter()
}
sourceSets {
test {
java {
srcDirs = ['test/main/java']
}
scala {
srcDirs = ['test/main/scala']
}
}
}
runOsgi {
bundles += project
}
bundle {
instruction '-dsannotations', '*'
}
test {
}
// Adding the Other Company Eclipse P2 project Core Repo as dependency
p2AsMaven {
group 'project', {
repo 'https://other-company.de/p2/'
iu 'de.other-company.project.core'
}
}
dependencies {
//compile fileTree(dir: 'libs', include: ['*.jar', '*.java'])
compile "org.osgi:org.osgi.core:6.0+"
compile "org.osgi:org.osgi.service.log:1.3+"
compile "org.osgi:org.osgi.service.component:1.3+"
compile "org.osgi:org.osgi.service.component.annotations:1.3+"
compile "project:de.other-company.project.core:+"
// Include the program repository code as dependency
//compile fileTree(dir: "../repository")
compile "org.scala-lang:scala-library:$scala_version+"
compile "com.typesafe.akka:akka-osgi_$scala_version:$akka_version+"
compile "io.circe:circe-core_$scala_version:$circe_version"
compile "io.circe:circe-generic_$scala_version:$circe_version"
compile "io.circe:circe-parser_$scala_version:$circe_version"
compile "io.circe:circe-optics_$scala_version:$circe_version"
compile "com.github.julien-truffaut:monocle-core_$scala_version:$monocle_version"
compile "com.github.julien-truffaut:monocle-macro_$scala_version:$monocle_version"
compile "org.slf4j:slf4j-api:1.7.+"
compile "org.slf4j:slf4j-simple:1.7.+"
compile "org.slf4j:osgi-over-slf4j:1.7.+"
testCompile "com.typesafe.akka:akka-testkit_$scala_version:$akka_version+"
testCompile "org.scalatest:scalatest_$scala_version:3.2+"
testCompile "org.scalactic:scalactic_$scala_version:3.2+"
testCompile "org.scalacheck:scalacheck_$scala_version:1.13+"
testCompile "org.mockito:mockito-core:2.+"
testRuntime "org.pegdown:pegdown:1.4+"
osgiRuntime "org.apache.felix:org.apache.felix.configadmin:1.8+"
osgiRuntime "org.apache.felix:org.apache.felix.scr:2.0+"
osgiRuntime "org.apache.felix:org.apache.felix.log:1.0+"
}
So I found the solution myself :)
I did some crappy solution to find and use files in the test.
After a research how to do it properly getClass.getResource("...") the problem went away.

java.util.zip.ZipException: duplicate entry: com/facebook/AccessToken$1.class

When I add facebook sdk dependencies to my android studio project, I have faced the issue :
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/facebook/AccessToken$1.class
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Please help me to resolve this issue .
Here is my build.gradle file :
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "24.0.1"
aaptOptions {
cruncherEnabled = false
}
defaultConfig {
applicationId "com.HN.xxx"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
debug {
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:support-v4:25'
compile ('com.facebook.android:facebook-android-sdk:4.+') {
exclude module: 'support-v4'
}
}
apply plugin: 'com.google.gms.google-services'

Android Gradle dexcount-gradle-plugin

I read the documentation but I could not make it. I am using Android Studio 2.0 Stable version.
This is my project level build.gradle file :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
// 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 app module level build.gradle file :
buildscript {
repositories {
mavenCentral() // or jcenter()
}
dependencies {
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.4.4'
}
}
apply plugin: 'com.getkeepsafe.dexcount'
apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.hugo'
dexcount {
format = "list"
includeClasses = false
includeFieldCount = true
includeTotalMethodCount = false
orderByMethodCount = false
verbose = false
maxTreeDepth = Integer.MAX_VALUE
teamCityIntegration = false
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "my_package_name"
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0.0"
}
buildTypes {
debug {
debuggable true
minifyEnabled false
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
debuggable false
minifyEnabled false
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions{
exclude 'META-INF/maven/commons-io/commons-io/pom.xml'
exclude 'META-INF/maven/commons-io/commons-io/pom.properties'
}
}
ext {
supportLibVersion = '23.3.0'
googlePlayServicesVersion = '8.4.0'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile "com.android.support:appcompat-v7:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
compile "com.android.support:percent:${supportLibVersion}"
compile "com.android.support:cardview-v7:${supportLibVersion}"
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.squareup.picasso:picasso:2.5.2'
// eventbus
compile 'org.greenrobot:eventbus:3.0.0'
// rate me dialog
compile 'com.github.hotchemi:android-rate:0.5.6'
// apache commons-io
compile group: 'commons-io', name: 'commons-io', version: '2.0.1'
}
this is giving error everytime :
Error:(11, 0) Dexcount plugin requires the Android plugin to be configured
what is the solution of this error ?
SOLUTION
I shifted the line of
"apply plugin: 'com.android.application'"
with
"apply plugin: 'com.getkeepsafe.dexcount'"
and it's worked
It is documented in Dex count's GitHub repo:
// make sure this line comes *after* you apply the Android plugin
apply plugin: 'com.getkeepsafe.dexcount'
So as you said, just make sure that the Android plugin is before the Dex count plugin.
apply plugin: 'com.android.application'
apply plugin: 'com.getkeepsafe.dexcount'

Android Log in with Twitter

I'm trying to integrate twitter login in my application, however not able to succeed yet.
https://dev.twitter.com/twitter-kit/android/twitter-login
In the above link it asks us to install Twitter Core library
dependencies {
compile('com.twitter.sdk.android:twitter-core:1.3.1#aar') {
transitive = true;
}
}
However, this library isn't being downloaded. I always throws an error
Failed to resolve: com.twitter.sdk.android:twitter-core:1.3.1
What should i do?
I have just solved your problem using the next instructions:
Inside your build.gradle (general):
your build script must be like this:
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
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
}
}
2.Your build.gradle (app) must be like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.yourappname"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile('com.twitter.sdk.android:twitter:1.5.1#aar') {
transitive = true
}
}
If you have any question, try to take a look this link:
https://github.com/twitter/twitter-kit-android
It works for me! Hope it helps!