0

Having an issue with Android Studio: I can run my android app the first time I hit "Run" (i.e. the green triangle). It will then start the AVD and load my application so I can test and debug it. But whenever I want to start the application again (i.e. typically after having done some modification) then the gradle build invariably end in:

   ...
   (!) Run Task
Android issues: 1 Error
   (!) Program type already present: android.support.v4.app.BackStackRecord$Op

The right hand side pane reads:

Program type already present: android.support.v4.app.BackStackRecord$Op
Message{kind=ERROR, text=Program type already present: android.support.v4.app.BackStackRecord$Op, sources=[Unknown source file], tool name=Optional.of(D8)}

Why is this not loading and restarting the new/modified version of the application. I located misc. threads that posed the same question but none of the advice given there helped me fix this. So I still always need to kill the AVD and restart it which is most tedious and time-consuming because it then always first needs to reboot! How can I fix this?

My application's gradle file reads:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "myapp.application.mmo.myapp"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:design:28.0.0-alpha3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

What am I missing? Why is this not working and replacing the installed app with the new version?

PS.: I won't claim that the previous Eclipse-based Android development environment was perfect. It was definitely far from that! But with that IntelliJ-based environment I have far more troubles and weirdoes! If things don't work here I always find it extremely difficult and time-consuming to figure out why something doesn't work!

mmo
  • 3,897
  • 11
  • 42
  • 63

1 Answers1

0

your build.gradle does not have any com.android.support:support-v4 (except possibly inside the libs directory, where it better should be deleted) and therefore I'd assume, that it had been edited until it does not match the error message anymore...

run ./gradlew :app:dependencies > ./dependencies.txt in the terminal to see what depends on support-v4 and then use exclude to make sure, that each library only exists once within a build configuration.

in order to debug, it's not this button: run, but this button: debug.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • Nope - I haven't edited anything in that file. It's what Android studio generated. I don't know gradle well enough, yet, to dare changing anything. It's still a book with seven seals for me. Thus - pardon my ignorance - but where exactly would I need to add this "com.android.support:support-v4" you mention or "use exclude"? – mmo Aug 04 '18 at 17:25
  • @mmo most likely you just have to delete your duplicate `support-v4` library from the `libs` directory, which may be a relic from the `ant` build... and I did not tell to add it anywhere, read closely. – Martin Zeitler Aug 05 '18 at 01:59
  • @mmo just explained it in another answer (another class, the same produce): https://stackoverflow.com/a/51695425/549372 – Martin Zeitler Aug 05 '18 at 19:00
  • Thanks! Indeed there was this android-support-v4.jar (or similar, don't recall the exact name) in the libs folder. That's where I had to add it when still developing under Eclipse. Deleted that and then things got better... – mmo Aug 06 '18 at 15:27