0

Gradle sync is not displaying any error while it is running but when I am trying to run the app it is displaying error.

I have tried to remove duplicate libraries and have added MultiDex.install(this); in my MainActivity and have tried to clean and run the project but with no luck.

The error:

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/fathzer/soft/javaluator/demo/DemoApplet.class

My gradle code:

 apply plugin: 'com.android.application'
 android {
 compileSdkVersion 26
 buildToolsVersion "26.0.0"
 defaultConfig {
 applicationId "com.example.kanwal.calculator_test"
 minSdkVersion 14
 targetSdkVersion 26
 versionCode 1
 versionName "1.0"
 testInstrumentationRunner                                                                    "android.support.test.runner.AndroidJUnitRunner"
 multiDexEnabled true }
 buildTypes {
 release {
 minifyEnabled false
 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-
 rules.pro'} } }
 dependencies {
 compile fileTree(include: ['*.jar'], dir: 'libs')
 compile 'com.android.support:multidex:1.0.1'
 androidTestCompile('com.android.support.test.espresso:espresso 
 core:2.2.2',{
 exclude group: 'com.android.support', module: 'support-annotations'
 })
 compile 'com.android.support:appcompat-v7:26.+'
 compile 'com.android.support.constraint:constraint-layout:1.0.2'
 testCompile 'junit:junit:4.12'
 compile files('libs/javaluator-3.0.1.jar')}
gulshan oad
  • 11
  • 1
  • 5
  • 1
    Please include your code as *text* and not as an image. Images can't be searched, can be hard to read for some users, and external images can disappear. – Thierry Lathuille Jul 01 '17 at 12:07
  • Ok I am publishing my gradle code here: – gulshan oad Jul 01 '17 at 12:10
  • dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:multidex:1.0.1' androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support annotations'}) compile 'com.android.support:appcompat-v7:26.+' compile 'com.android.support.constraint:constraint-layout:1.0.2' testCompile 'junit:junit:4.12' compile files('libs/javaluator-3.0.1.jar')} – gulshan oad Jul 01 '17 at 12:12
  • 1
    Please edit your question instead of posting it in the comments, it will be easier to find and read! – Thierry Lathuille Jul 01 '17 at 12:15
  • I have just updated my question. – gulshan oad Jul 01 '17 at 12:31

2 Answers2

0

Exclude your duplicate package from the jar:

compile('libs/javaluator-3.0.1.jar') {
exclude module: 'demo';}

Try to run this on terminal in root directory of your proyect:

./gradlew clean
Daniel RL
  • 353
  • 1
  • 12
  • I run that command in terminal and it displayed this: '.' is not recognized as an internal or external command, operable program or batch file. And when removed the (.) then it displayed this: '/gradlew' is not recognized as an internal or external command, operable program or batch file. – gulshan oad Jul 01 '17 at 09:36
  • Go to gradle tab on the right side in Android Studio and run clean command from there. http://imgur.com/a/FYL6j – Daniel RL Jul 01 '17 at 09:42
  • I followed your instructions to clean, it's error free now but still not running the application in my device. Plus after running the app it turns all the R red in the MainActivity. – gulshan oad Jul 01 '17 at 11:05
  • Whats happens now? Describe the problem as much as you can – Daniel RL Jul 01 '17 at 11:08
  • The app is error free now, but after running the app all the R in the MainActivity turned red in color. And app is not running in my device. – gulshan oad Jul 01 '17 at 11:10
  • event log is displaying this: InvalidVirtualFileAccessException: Accessing invalid virtual file: file://C:/Users/sanjay/AndroidStudioProjects/Calculator-Test/build/android-profile; original:261254; found:- – gulshan oad Jul 01 '17 at 11:44
  • I found this https://stackoverflow.com/a/38057842/4845438 but I do not know exactly what may be going on – Daniel RL Jul 01 '17 at 16:43
  • I have tried those instructions as well but still my app is not running. I have updated the AS earlier may be that is the issue but don't know what versions to use for sdk or other elements which should be compatible be with each other. – gulshan oad Jul 01 '17 at 16:59
0

You added this line to your gradle.

compile fileTree(include: ['*.jar'], dir: 'libs')

You can either remove the redundancy lines or remove the above line itself.

By removing the above line

enter image description here

Abhi
  • 3,431
  • 1
  • 17
  • 35