Stop Android Studio from using Support Library

2019-04-24 18:18发布

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.

3条回答
够拽才男人
2楼-- · 2019-04-24 19:01

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.

查看更多
The star\"
3楼-- · 2019-04-24 19:09

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.

查看更多
家丑人穷心不美
4楼-- · 2019-04-24 19:12

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.

查看更多
登录 后发表回答