• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Adding support-v4 library as dependency in Android Studio project?

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm following Big Nerd Ranch Guide (edition from 2015). In chapter 7, we are starting with fragments. The author explained why we should use support libraries, like this:

Authors wrote:The support library includes a complete implementation of fragments that work all the way back
to API level 4. In this book, we will use the support implementation of fragments rather than the
implementation built into the Android OS. This is a good idea because the support library is quickly
updated when new features are added to the fragments API. To use those new features, you can update
your project with the latest version of the support library.



I followed their instructions on how to add app dependencies. My build.gradle (Module app) file, looks like this:



In my Activity, android studio is complaining:


Saying: Cannot resolve Fragment, FragmentActivity, FragmentManager. I also tried some suggestions from SO:

1. File -> Invalidate Chaches / Restart
2. File -> Sync Project With Gradle Files

None worked. How do I get around this?
 
Saloon Keeper
Posts: 6385
158
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you intend to use the v4 Fragment implementation, then you should not import AndroidX classes of the same name. That's bound to cause problems.
 
Mike Gosling
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The same problem persists. I repeated the process of creating new project, without deleting androidX in dependencies.
 
Tim Moores
Saloon Keeper
Posts: 6385
158
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just checked with my main app, and it has the following dependencies:



But then, I switched to extending android.support.v7.app.AppCompatActivity rather than android.support.v4.app.FragmentActivity (the latter is getting a bit long in the tooth, and the former extends it, so there should be few issues using that instead).
 
Mike Gosling
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did you type in Search box for adding dependencies to get android.support.v7.app.AppCompatActivity ?
 
Tim Moores
Saloon Keeper
Posts: 6385
158
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't use Android Studio. I probably copied the lines from whatever blog post on the Android developer site talked about the v7 class.
 
Surfs up space ponies, I'm making gravy without this lumpy, tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic