简体   繁体   中英

Stop Android Studio from using Support Library

I'm trying to get my Android project in Android Studio to NOT use the Support library. My issue is that when I use fragments it is expecting support fragments and causing the app to crash.

My Min SDK is 14 and my Target SDK is 19. My understanding is that because I'm targeting these versions I should not need the support library. Correct me if I'm wrong.

I'm trying to correct this error java.lang.ClassCastException: com.google.android.gms.maps.MapFragment cannot be cast to android.support.v4.app.Fragment . And I am aware I can fix it by just using SupportMapFragment instead. But I do not want to do this. I want to use the regular MapFragment

So my main question is how can I get it to stop expecting support library fragments and just use regular fragments. I've also had this issue with other fragments not just the map.

I'm surprised no one can still give you a straight forward answer. I hope my response will help.

So to stop Android Studio from using support library especially the infamous AppCompat v7, follow these few steps:

1) Gradle Scripts > build.gradle(Module: app)

2) Remove the line that says compile 'com.android.support:appcompat-v7:22.1.1'

3) res/values/styles.xml > change the parent value to: parent="@android:style/Theme.Holo.Light"

4) AndroidManifest.xml > change the application android:theme to: android:theme="@android:style/Theme.Holo.Light"

5) Go into your activities and remove the line that imports the support library. Change it to: import android.app.Activity;

6) Now in the menu bar: Build > ReBuild Project. Correct any errors then keep rebuilding until you get it to work, then run your project to ensure nothing crashes and your references are in order.

For me I got errors stating that I app:ShowAsAction is not supported or so. I had to change it to android:ShowAsAction. Just Make sure that for any error, you read it carefully and follow the suggestions in the little dialogues boxes that pop up beside the error line.

To completly remove the suppport library, go to the package explorer window, and in

your project name -> libs

remove the android-support-v4.jar. If you do that, remove all imports startng with android.support.v4 and replace them with apropriate (non support) imports.

If you've removed the support library from the build.gradle , and there's no file in the libs folder, have you made sure to delete the imports?

From the error message, it looks like you'll have the following import (else the error wouldn't know about trying to cast to a support Fragments) at the top of your class:

import android.support.v4.app.Fragment;

Delete this, replace it with:

import android.app.Fragment;

Do this with all the support references.

You can add this code to app gradle file to avoid using support v4 lib

android {
configurations.all {   //this piece is important to avoid duplicates
        exclude group: 'com.android.support',
                module: 'support-v4'
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM