Stop Android Studio from using Support Library

ⅰ亾dé卋堺 提交于 2019-12-07 02:33:57

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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'
    }
}


来源:https://stackoverflow.com/questions/20062094/stop-android-studio-from-using-support-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!