4

The Problem is that , I'm getting error while generating Signed APK using Allatori Java Obfuscator. I tried different hacks like, Invalidate and Clear cache /Restart,by deleting build folder, rebuilding project, Strings , Even tried comparing package names ,Class Naming conventions,possible jars, deprecated methods or classes but Its of no use.! Multi Dex is enabled as well.! and I tried every possible Solution but unable to generate signed APK.

apply plugin: 'com.android.application'
apply plugin: 'ensighten'


ext {
    supportVersion = "25.3.1"
    googleServices = "11.4.2"
}

android {

    def version = "2.0.0"
    compileSdkVersion 25
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "removed"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 20
        versionName "${version}"
        multiDexEnabled true


        def today = new Date().format('yyyyMMdd_HHmmss').toString()
        project.ext.set("archivesBaseName", "MyApplication_Android_Build_"+ today + "_Version " + version);

    }



   
    applicationVariants.all { variant ->
        variant.javaCompile.doLast {
            runAllatori(variant)
        }
    }

    buildTypes {
        debug {
            buildConfigField "boolean", "LOG_ENABLED", "true"
            buildConfigField "boolean", "SSL_ENABLED", "true"
        
            buildConfigField "String", "SERVER_URL", "\"http:///\""
        }
        release {
            buildConfigField "String", "SERVER_URL", "\"http://\""
            buildConfigField "boolean", "LOG_ENABLED", "false"
            buildConfigField "boolean", "SSL_ENABLED", "true"
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        abortOnError false
    }

}

android {
    aaptOptions {
        cruncherEnabled = false
    }
}

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }

        maven { url "https://ensighten-mobile.bintray.com/maven" }
        mavenCentral()
    }
    dependencies {
        classpath 'io.fabric.tools:gradle:1.22.1'
        classpath "com.ensighten.plugin.android:ensighten:2.0.1"
    }
}

apply plugin: 'io.fabric'

repositories {
    maven { url "https://jitpack.io" }
    maven { url 'https://maven.fabric.io/public' }
    maven { url "http://dl.bintray.com/vividadmin/maven" }
    maven { url "https://ensighten-mobile.bintray.com/maven" }
    mavenCentral()
    google()
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile project(':williamchart')
    compile "com.android.support:appcompat-v7:${project.ext.supportVersion}"
    compile "com.android.support:design:${project.ext.supportVersion}"
    compile "com.android.support:percent:${project.ext.supportVersion}"
    compile "com.android.support:cardview-v7:${project.ext.supportVersion}"
    compile "com.android.support:recyclerview-v7:${project.ext.supportVersion}"
    compile "com.android.support:animated-vector-drawable:${project.ext.supportVersion}"
    compile "com.android.support:gridlayout-v7:${project.ext.supportVersion}"


    compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
        transitive = true;
    }

    compile "com.google.firebase:firebase-crash:${project.ext.googleServices}"
    compile "com.google.firebase:firebase-core:${project.ext.googleServices}"
    compile "com.google.firebase:firebase-invites:${project.ext.googleServices}"
    compile "com.google.firebase:firebase-messaging:${project.ext.googleServices}"
    compile "com.google.android.gms:play-services-analytics:${project.ext.googleServices}"



    compile 'com.android.support:multidex:1.0.2'
    compile 'com.android.volley:volley:1.0.0'
    compile 'net.danlew:android.joda:2.9.2'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.scottyab:aescrypt:0.0.1'
    compile 'net.cachapa.expandablelayout:expandablelayout:2.9.1'
    compile 'com.facebook.android:facebook-android-sdk:4.23.0'
    compile 'com.ensighten.android:ensighten-core:2.4.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.code.gson:gson:2.8.1'
    testCompile 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'

def runAllatori(variant) {
    copy {
        from "$projectDir/allatori.xml"
        into "$buildDir/intermediates/classes/"
        expand(classesRoot: variant.javaCompile.destinationDir,
                androidJar: "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar",
                classpathJars: variant.javaCompile.classpath.getAsPath(),
                logFile: "allatori-log-${variant.name}.xml")
        rename('allatori.xml', "allatori-${variant.name}.xml")
    }

    new File("${variant.javaCompile.destinationDir}-obfuscated").deleteDir()
    javaexec {
        main = 'com.allatori.Obfuscate'
        classpath = files("$rootDir/allatori/allatori.jar")
        args "$buildDir/intermediates/classes/allatori-${variant.name}.xml"
    }
    new File("${variant.javaCompile.destinationDir}").deleteDir()
    new File("${variant.javaCompile.destinationDir}-obfuscated").renameTo(new File("${variant.javaCompile.destinationDir}"))
}

Error:

Error:Error converting bytecode to dex: Cause: PARSE ERROR: class name (com/pckg/pakistan/myapplication/R) does not match path (com/pckg/pakistan/myapplication/r.class) ...while parsing com/pckg/pakistan/myapplication/r.class

Error:Execution failed for task ':app:transformClassesWithDexForRelease'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Return code 1 for dex process

Atif AbbAsi
  • 4,649
  • 4
  • 21
  • 45
  • 1
    It is showing 4 errors could you please post the complete error? – lib4 Dec 29 '17 at 17:20
  • Possible duplicate of [Android- Error:Execution failed for task ':app:transformClassesWithDexForRelease'](https://stackoverflow.com/questions/35890257/android-errorexecution-failed-for-task-apptransformclasseswithdexforrelease) – Yuliwee Dec 29 '17 at 17:42
  • @Yuliwee nope its not.! – Atif AbbAsi Dec 29 '17 at 17:53
  • So you have already tried all solutions in the mentioned post and it didn't work? – Yuliwee Dec 29 '17 at 17:55
  • @Yuliwee Yup I tried all possible solutions but unable to resolve.! – Atif AbbAsi Dec 29 '17 at 17:59
  • @AtifAbbAsi If so, please provide more information in your question. What have you tried so far? You only wrote you did a clear and restart and enabled multidex. If using gradle, please provide your build.gradle. – Yuliwee Dec 29 '17 at 18:07
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/162184/discussion-between-atif-abbasi-and-yuliwee). – Atif AbbAsi Dec 29 '17 at 18:20
  • Signed apk should be release version, are u trying debug or release verion. As the exception shows class paths points to debug. Are u sure all your modules in release mode. – lib4 Dec 29 '17 at 18:22
  • Yup its in release mode.! – Atif AbbAsi Dec 29 '17 at 18:27
  • post the whole build.gradle file here. – Sardar Khan Jan 01 '18 at 05:01

2 Answers2

0

As per my knowledge you are using lot of libraries and using Allatori Java Obfuscator due to Allatori obfuscation your java code is not being properly converted into byte code and thats the reason you are unable to generate signed apk. Try a quick hack delete build files ,gradle files and invalidate and restart your project more than once

Hope this may help u :)

Ghulam Qadir
  • 421
  • 3
  • 11
-1

There is no Signing config in Gradle you have added, So first Create a Keystore (https://developer.android.com/studio/publish/app-signing.html)

and then add in the app level Gradle

signingConfigs {
    release {
        // For making app store release config below parameters
        storeFile file('path to keystore')
        storePassword "keystore password"
        keyAlias "Alias_of_keystore"         
        keyPassword "Keystore Password"   
    }
}

after that in build types add

 buildTypes {
    // For  app store release uncomment below and select release build flavor in Build Variants
    release {
...
signingConfig signingConfigs.release
}}
Kousei
  • 1,301
  • 1
  • 8
  • 16