Error in build apk - android

my error message is:
//Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/common/annotations/Beta;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)//
please help me to fix this
my build.gradle
//dependencies {
compile project(':appRater')
compile project(':circularImageView')
compile project(':facebookSDK')
compile project(':paperSlidingTab')
compile project(':library')
compile project(':urlImageViewHelper')
compile project(':pullToRefreshLi')
compile project(':libraries:SlidingMenu:library')
compile files('libs/GoogleAdMobAdsSdk-6.4.1.jar')
compile files('libs/httpmime-4.2.5.jar')
compile files('libs/json-org.jar')
compile files('libs/universal-image-loader-1.9.1-with-sources.jar')
compile files('libs/WebSocket.jar')
compile files('libs/gcm.jar')
compile files('libs/applause-sdk-library-2.0.0.jar')
compile 'org.droidparts:droidparts:1.+'
compile 'joda-time:joda-time:2.3'
compile 'com.google.api-client:google-api-client:1.+'
compile 'com.google.api-client:google-api-client-android2:1.+'
compile 'com.google.http-client:google-http-client:1.+'
compile 'com.google.http-client:google-http-client-android2:1.+'
compile 'com.google.oauth-client:google-oauth-client:1.+'
compile 'com.google.code.gson:gson:2.+'
compile 'com.google.guava:guava:11.+'
compile 'com.google.http-client:google-http-client-jackson2:1.+'
compile 'com.google.protobuf:protobuf-java:2.+'
compile 'com.google.android.gms:play-services:3.+'
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 17
}
signingConfigs {
release {
if (System.getenv("GRADLE_KEYSTORE")) {
storeFile = file(System.getenv("GRADLE_KEYSTORE"))
storePassword = System.getenv("GRADLE_KEYSTORE_PASSWORD")
keyAlias = System.getenv("GRADLE_KEY_ALIAS")
keyPassword = System.getenv("GRADLE_KEY_PASSWORD")
}
}
}
buildTypes.debug {
ext.enableCrashlytics = false
}
buildTypes.release {
debuggable false
zipAlignEnabled true
minifyEnabled false
signingConfig signingConfigs.release
}
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'
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}

This appear when we use same library with 2 or more versions in one project. So try to find the versions of libraries in your app especially support-v4 library
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 19
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
You can use below code too , This work in mine case
dexOptions {
incremental true
javaMaxHeapSize "4g"
}

defaultConfig {
minSdkVersion 14 //lower than 14 doesn't support multidex
targetSdkVersion 22
// Enabling multidex support.
multiDexEnabled true
}
or you can do by make an Application class
public class MyApplication extends MultiDexApplication { .. }
or
override
attachBaseContext method and call MultiDex.install().
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
Otherwise (if your application does not have custom Application implementation), declare MultiDexApplication as application implementation in your AndroidManifest.xml.
<application
android:name="android.support.multidex.MultiDexApplication"
.. >
..
</application>

Related

Start activity on kitkat devices

This is thrown when trying to open activity using context.startActivity(intent)
java.lang.TypeNotPresentException: Type android/support/v4/app/ActivityCompat$SharedElementCallback23Impl not present
All activities extends AppCompatActivity and I am calling AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) inside a static block of my application.
On newer android versions everyting is ok.
Does anybody met this issue and can share info how to solve it?
Here my gradle configuration
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
lintOptions {
disable 'RestrictedApi'
}
signingConfigs {
release {
keyAlias '****'
keyPassword '*************'
storeFile file('../release.jks')
storePassword '*************'
}
}
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "***.****"
minSdkVersion 19
targetSdkVersion 26
versionCode 8
versionName "1.0.3"
vectorDrawables.useSupportLibrary true
multiDexEnabled true
renderscriptTargetApi 26
renderscriptSupportModeEnabled true
signingConfig signingConfigs.release
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
jcenter()
}
maven {
url 'https://maven.google.com'
// Alternative URL is 'https://dl.google.com/dl/android/maven2/'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':googleemoji')
compile('com.google.api-client:google-api-client-android:1.22.0') {
exclude module: 'httpclient'
exclude group: 'org.apache.httpcomponents'
}
compile('com.google.http-client:google-http-client-gson:1.22.0') {
exclude module: 'httpclient'
}
compile('com.google.apis:google-api-services-gmail:v1-rev44-1.22.0') {
exclude group: 'org.apache.httpcomponents'
}
compile 'com.google.firebase:firebase-auth:11.4.0'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
//noinspection GradleCompatible
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:customtabs:26.1.0'
compile 'com.android.support:support-vector-drawable:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.google.android.gms:play-services-identity:11.4.0'
compile 'com.google.firebase:firebase-messaging:11.4.0'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.google.android.gms:play-services-auth:11.4.0'
compile 'com.google.android.gms:play-services-plus:11.4.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'commons-io:commons-io:2.5'
compile 'com.google.android.gms:play-services-location:11.4.0'
compile 'com.google.firebase:firebase-invites:11.4.0'
}
kotlin {
experimental {
coroutines "enable"
}
}
apply plugin: 'com.google.gms.google-services'

Not able to install release apk for product flavors

I have generated my signed apk for product flavors, but when i try to install the apk in my device, it says "App not installed"
Here is my gradle file code :-
android {
compileSdkVersion 25
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.app.olivesync"
minSdkVersion 14
targetSdkVersion 25
multiDexEnabled true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/DEPENDENCIES'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors{
main {
applicationId "com.app.olivesync"
}
resonance {
applicationId "com.app.resonance"
}
}
dependencies {
compile('com.fasterxml.jackson.core:jackson-annotations:2.2.2') {
exclude group: 'com.fasterxml.jackson.core'
}
compile('com.fasterxml.jackson.core:jackson-databind:2.2.3') {
exclude group: 'com.fasterxml.jackson.core'
}
compile('com.fasterxml.jackson.core:jackson-core:2.2.3') {
exclude group: 'com.fasterxml.jackson.core'
}
compile 'com.android.support:support-v4:25.3.0'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.roomorama:caldroid:3.0.1'
compile 'com.android.support:design:25.3.0'
compile 'com.google.android.gms:play-services-gcm:10.2.0'
compile 'com.microsoft.azure:notification-hubs-android-sdk:0.4#aar'
compile 'com.microsoft.azure:azure-notifications-handler:1.0.1#aar'
compile 'com.google.firebase:firebase-crash:10.2.0'
compile 'com.github.shell-software:fab:1.1.2'
compile 'com.android.support:cardview-v7:25.3.0'
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.github.iammert:MaterialIntroView:1.6.0'}
repositories {
maven { url "https://jitpack.io" }
}
apply plugin: 'com.google.gms.google-services'
change your version and then try to build sign apk. Hope it will work.

Android Gradle build error while running the project

I have mentioned my gradle below please let me know what is the solution for that question and have used the api level 25 in my project
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
signingConfigs {
config {
keyAlias 'yaksha'
keyPassword '123456'
storeFile file('/home/abhinav/Downloads/yaksha.jks')
storePassword '123456'
}
}
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.tene.yaksha"
minSdkVersion 17
targetSdkVersion 21
versionCode 1
versionName "1.0"
multiDexEnabled true
testApplicationId "com.tene.yaksha1"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
testHandleProfiling true
testFunctionalTest true
}
testOptions {
reportDir "$rootDir/test-reports"
resultsDir "$rootDir/test-results"
}
dataBinding {
enabled = true
}
dexOptions {
//incremental = true;
preDexLibraries = false
javaMaxHeapSize "4g"
}
lintOptions {
// lintConfig file("$project.rootDir/tools/rules-lint.xml")
abortOnError false
htmlOutput file("$project.buildDir/outputs/lint/lint.html")
warningsAsErrors false
xmlReport true
}
buildTypes {
release {
minifyEnabled true
debuggable false
jniDebuggable true
signingConfig signingConfigs.config
renderscriptDebuggable true
shrinkResources true
proguardFile '/home/abhinav/Android/Sdk/tools/proguard/yakshaproguard.txt'
}
debug {
minifyEnabled false
proguardFile '/home/abhinav/Android/Sdk/tools/proguard/yakshaproguard.txt'
multiDexKeepFile file('multidex-config.txt')
}
}
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'
}
testOptions {
unitTests.returnDefaultValues = true
unitTests {
all {
jvmArgs '-XX:MaxPermSize=256m'
if (it.name == 'testDebug') {
systemProperty 'debug', 'true'
}
if (it.name == 'connectedDebugAndroidTest') {
}
}
}
}
configurations {
}
}
dependencies {
// compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support:design:25.3.0'
compile 'com.google.code.gson:gson:2.7'
compile 'com.google.android.gms:play-services:10.2.1'
compile project(':realmtenedbservice')
compile project(':tenewsrestlib')
compile project(':TeneLocationLib')
compile project(':SecurityYsc')
compile project(':library')
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:recyclerview-v7:25.3.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.birbit:android-priority-jobqueue:2.0.1'
compile 'com.fasterxml.jackson.core:jackson-core:2.7.3'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.3'
compile 'io.reactivex:rxjava:1.1.0'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.google.maps.android:android-maps-utils:0.4+'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'io.realm:android-adapters:1.4.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.sromku:simple-storage:1.2.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'joda-time:joda-time:2.9.7'
compile 'id.zelory:compressor:1.0.4'
compile 'io.reactivex:rxandroid:1.2.1'
}
I'm getting this error while running the project,can you anybody give suggesions why this is coming
Information:Gradle tasks [:app:assembleDebug]
Warning:Using incompatible plugins for the annotation processing: android-apt. This may result in an unexpected behavior.
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/commons/io/CopyUtils.class
Information:BUILD FAILED
Information:Total time: 18.768 secs
Information:1 error
Information:1 warning
Information:See complete output in console
You can exclude that class, which is showing duplicate like as
configurations {
all*.exclude group: 'org.apache.commons'
}
I thik this is duplicate
compile 'com.android.support:multidex:1.0.1'

DOCX4J in Android Studio with Multidex gives duplicate entry error for libraries

I am trying to get all the libraries for docx4j obtained here:
https://stackoverflow.com/a/23710079/1616685
I set up MultiDex successfully, however I get a duplicated entry error:
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'. > java.util.zip.ZipException: duplicate entry: org/apache/harmony/awt/internal/nls/Messages.class
as you can see there are a lot of libraries to compile... it is easy to have duplicates, is there a way to avoid from the gradle such errors?
here the gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "com.example.test_images"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
}
dexOptions {
preDexLibraries = false
// incremental true
javaMaxHeapSize "4g"
incremental true
}
productFlavors {
}
compileOptions {
}
}
subprojects {
project.plugins.whenPluginAdded { plugin ->
if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) {
project.android.dexOptions.preDexLibraries = false
} else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
project.android.dexOptions.preDexLibraries = false
}
}
}
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = ['--multi-dex']
} else {
dx.additionalParameters += '--multi-dex'
}
}
}
dependencies {
compile ('com.android.support:multidex:1.0.0'){ exclude group: 'java.util.zip' }
compile ('com.android.support:appcompat-v7:22.2.0')
compile ('com.parse.bolts:bolts-android:1.+')
compile files('libs/activation.jar')
compile files('libs/additionnal.jar')
compile files('libs/ae-awt.jar')
compile files('libs/ae-docx4j-2.8.0-SNAPSHOT.jar')
compile files('libs/ae-jaxb-2.2.5.jar')
compile files('libs/ae-xmlgraphics-commons.jar')
compile files('libs/avalon-framework-api-4.3.1.jar')
compile files('libs/avalon-framework-impl-4.3.1.jar')
compile files('libs/commons-codec-1.3.jar')
compile files('libs/commons-io-1.3.1.jar')
compile files('libs/commons-lang-2.4.jar')
compile files('libs/commons-logging-1.1.1.jar')
compile files('libs/droidText.0.4.jar')
compile files('libs/istack-commons-runtime.jar')
compile files('libs/JAXBNamespacePrefixMapper-2.2.4.jar')
compile files('libs/jaxp-datatype.jar')
compile files('libs/log4j-1.2.15.jar')
compile files('libs/serializer-2.7.1.jar')
compile files('libs/stringtemplate-3.2.1.jar')
compile files('libs/txw2-20110809.jar')
compile files('libs/w3c-css.jar')
// compile 'com.android.support:support-annotations:22.2.0'
// compile 'com.android.support:multidex:1.0.0'
}
https://github.com/plutext/Docx4j4Android4/ is an Android Studio project; it uses Maven shade plugin to repackage org.apache.http

java.exe finished with non-zero exit value 2

My previous play service version is 6.5.87 and I upgraded to 7.0.0 then Got this error
com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException: Process 'command
'C:\Program Files\Java\jdkx.x.x_xx\bin\java.exe'' finished with
non-zero exit value 2
compile 'com.google.android.gms:play-services:6.5.87'
I have upgraded play service Then....Now my gradle is
dependencies {
compile project(':com_facebook_android')
compile project(':pullToRefreshLib')
compile project(':smoothProgressbarLib')
compile project(':progressMaterial')
compile 'com.android.support:support-v4:22.0.0'
compile 'com.google.android.gms:play-services:7.0.0'
compile 'com.google.code.gson:gson:2.3'
compile 'com.jakewharton:butterknife:6.1.0'
compile files('libs/android-async-http-1.4.6.jar')
compile files('libs/commons-io-2.4.jar')
compile files('libs/google-api-client-1.4.1-beta.jar')
compile files('libs/google-api-client-googleapis-1.4.1-beta.jar')
compile files('libs/jackson-core-asl-1.6.7.jar')
compile files('libs/jeval.jar')
compile files('libs/jscience.jar')
compile files('libs/libGoogleAnalyticsV2.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/universal-image-loader-1.9.3.jar')
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile files('libs/guava-r09.jar')
Is there any conflict library?
No one answered. I found.... The solution is multidex
public class MyApplication extends MultiDexApplication {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
in menifest file
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:largeHeap="true"
android:theme="#style/Theme.MyAppTheme">
My gradle file
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.winapp"
minSdkVersion 14
targetSdkVersion 21
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
}
dexOptions {
preDexLibraries = false
incremental true
javaMaxHeapSize "4g"
}
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = ['--multi-dex']
} else {
dx.additionalParameters += '--multi-dex'
}
}
}
}
You will be able to include to your gradle only Google Play Services API that you will use. In this link you should select the URIs to compile in your project https://developers.google.com/android/guides/setup#split
For example, if you would include only Google analytics you should add only this in your gradle project file
compile 'com.google.android.gms:play-services-analytics:8.1.0'

Categories

Resources