0

I have multiple widgets that you would normally initialize like this,

 public EditText editTextTitle;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_job);

    editTextTitle = findViewById(R.id.editTxtTitle);
}

but then it gives me this errorenter image description here

However when I go to my xml it shows that it is in fact an editText.

This all happened when I changed my build.gradle(app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.worktide.worktide"
        minSdkVersion 21
        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'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.google.firebase:firebase-core:17.0.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.firebase:firebase-firestore:20.2.0'
    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'
    implementation 'com.mikhaellopez:circularimageview:3.2.0'
}

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

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            // Skip multidex because it follows a different versioning pattern.
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.0'
            }
        }
    }
}

EDIT

I am pretty sure my xml has nothing to do with this problem that I get after removing the multidexing. enter image description here

Kristofer
  • 809
  • 9
  • 24

1 Answers1

2

You are using multidexing in a wrong way. Refer to the following reference. https://developer.android.com/studio/build/multidex.html

Also, you should migrate to androidx for getting new features and upgrades on existing support library.

Remove the following code since it is trying to use old versions of support library.

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            // Skip multidex because it follows a different versioning pattern.
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.0'
            }
        }
    }
}

The build.gradle file should be after removing above code block

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.worktide.worktide"
        minSdkVersion 21
        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'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.google.firebase:firebase-core:17.0.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.firebase:firebase-firestore:20.2.0'
    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'
    implementation 'com.mikhaellopez:circularimageview:3.2.0'
}

If problem exists even after syncing gradle file. You might need to invalidate caches and restart from File -> Invalidate Caches/Restart.

Update

After fixing multidexing related code following error was observed

Merger Manifest Failed

It is caused by the mixing of androidx library com.mikhaellopez:circularimageview:3.2.0 on non-androidx project. The project should be migrated to andoridx to use androidx libraries.

Note: Androidx project can use older support version libraries.

Sagar Chapagain
  • 1,683
  • 2
  • 16
  • 26
  • To add on, if the OP does not delete the code, then he/she must use casting. – SnakeException Jul 28 '19 at 16:25
  • Since the type of `editTextTitle` is already specified, casting is not necessary when calling `findViewById()` starting with API level 26. – Sagar Chapagain Jul 28 '19 at 16:29
  • But as you can see, if the OP does not delete the code, the OP must do so because of his/her minSdkVersion (21). – SnakeException Jul 28 '19 at 16:30
  • Hi if I remove this it actually gives me this error, https://stackoverflow.com/questions/43280871/android-getting-manifest-merger-failed-error-after-updating-to-a-new-version – Kristofer Jul 28 '19 at 16:32
  • @InsurgentPointerException minSdkVersion 21 will not cause any problem since the change in `findViewById` is backward compatible too. – Sagar Chapagain Jul 28 '19 at 16:34
  • Ah, fair. Thank you – SnakeException Jul 28 '19 at 16:34
  • @Kristofer use 28.0.0 for support version libs now and follow the multidexing as mentioned in android developer doc. Do gradle sync properly, you won't be getting any problem. – Sagar Chapagain Jul 28 '19 at 16:37
  • @SagarChapagain but I already have 28.0.0 in my code as you can see on the build.gradle, so what should I change? – Kristofer Jul 28 '19 at 16:38
  • @Kristofer I had updated the answer. If problem still occurs, edit your question and include the content of layout file `activity_create_job `. – Sagar Chapagain Jul 28 '19 at 16:45
  • @Kristofer you are getting the `merger manifest failed` because one of the library used `com.mikhaellopez:circularimageview:3.2.0` uses androidx component which differs from `com.android.support` variants used in your project. So you are getting that problem. I suggest you to migrate to androidx via `Refactor -> Migrate to AndroidX`. Migration process is very stable and you won't get any issues. – Sagar Chapagain Jul 28 '19 at 16:59
  • @Kristofer I had updated the answer again to include your merger manifest failed error. – Sagar Chapagain Jul 28 '19 at 17:09