Kodeco Forums

Android Fragments Tutorial: An Introduction with Kotlin

In this Android Fragments with Kotlin tutorial you will learn the fundamental concepts of fragments while creating an app that displays rage comics.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/361-android-fragments-tutorial-an-introduction-with-kotlin

Where can I find the old java tutorial?

Hello, according to Ray “we don’t link to the old java tutorials at the moment we just publish the latest and greatest this will change some day when we get version tracking on our tutorials, but that’s the way it is right now :]” so unfortunately there is not way to get the old tutorial. The concepts should be the same with the difference being the language. Hope this helps!

Hello, Can I get old java project ? I dont use Kotlin and I need the java code example. Is there any chance/way of getting the old code ?

We only keep the most recent tutorial’s version on the website at the moment. Thank you!

On first import I am getting errors and can’t proceed.

Data Binding annotation processor version needs to match the Android Gradle Plugin version. You can remove the kapt dependency com.android.databinding:compiler:3.0.0-beta2 and Android Gradle Plugin will inject the right version.

Removing the kapt line results in another error about the Manifest.

Manifest merger failed : Attribute meta-data#android.support.VERSION@value value=(26.0.1) from [com.android.support:appcompat-v7:26.0.1] AndroidManifest.xml:28:13-35 is also present at [com.android.support:recyclerview-v7:26.1.0] AndroidManifest.xml:25:13-35 value=(26.1.0). Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:26:9-28:38 to override.

So then I added the meta-data and now

Manifest merger failed with multiple errors, see logs

@lgleason Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hello, sorry about the delay responding to this.

The issue you are encountering appears to be because you are running a more recent version of Gradle in your IDE than when this tutorial was created. We are going to need to update this in the download files for the tutorial, but it is a moving target since the versions are incremented on a regular basis. In the meantime this brings up something you are likely to run into when opening up other projects and examples you come across on the Internet. I can’t tell from your message which version of Android Studio you are running, but I am running 3.0.1 on MacOS and will share what I did to get around this. While loading the project you probably were presented with a message that looks something like the attached image.

Most likely you took the conservative route with this project and chose to not update the Gradle file in this project. That is generally what I would have done first as well. In this case however, given that these examples are currently using old beta versions of Gradle it is too far back for the IDE to be able to readily support this. While you could go down the path of downloading a older version of Android Studio in order to use this project, that is not really necessary. In this case the better option is to update the project to the lates version of Gradle which will fix this issue.

There are two ways you can do that. One is to delete the project directory, and do a fresh unzip of the project. Then click update when you are presented with this dialog. The other option is to change the line
in the project build.gradle from:
classpath ‘com.android.tools.build:gradle:3.0.0-beta5’
to:
classpath ‘com.android.tools.build:gradle:3.0.1’
which is the current version Gradle at this time. (if someone is reading this a few months from now you may need to adjust this version to the latest version of Gradle at the time you are reading this). Please let us know if this works for you or if you have any additional questions.

Greetings, @lgleason !

First of all, thank you for writing the excellent tutorial :]

I just went through the tutorial but I think there may be something missing in the starter project. Specifically, it seems that com.raywenderlich.alltherages.databinding.FragmentRageComicDetailsBinding is not being built and hence we won’t be able to use it in RageComicDetailsFragment.kt.

I checked the final project and com.raywenderlich.alltherages.databinding.FragmentRageComicDetailsBinding is there with no problem after I built the project. I’ve tried to clean/rebuild with the starter project but it is still missing. I’m not really familiar with Gradle so I’m not sure what’s wrong. Any help would be appreciated!

@lgleason Do you have any feedback regarding this? Thank you - much appreciated! :]

@peng90 The most common causes of the binding object not being created are:

  • Not having the dataBinding reference in your app Gradle file

  • Not having the enclosing layout in the view

  • There is another problem somewhere in the project and the build is never getting to the stage where it generates the binding objects

Since “dataBinding { enabled = true }” is in the beginning sample project app level build.gradle we can safely rule that out. The next step would be to see if the project compiles successfully without a reference to that binding class (by commenting out any references to it in RageComicDetailsFragment.kt). If it doesn’t then you probably have syntax error somewhere else in your project. If it does build and run successfully this is probably a issue with the fragment_rage_comic_details.xml layout. Check that and see if you have all of the text from the tutorial copied and also make sure that something crazy didn’t get introduced during that process. You could copy the layout from the final project over to the one in your in process project that you are working through as a sanity check. If that doesn’t work another option could be to clear the Invalidate Caches/Restart option under the File menu. Hopefully one of those options will get you past that issue. If not please let me know and we will dig further.

Hi @lgleason, thanks for answering my question!

It turns out I did forget to change the enclosing layout in fragment_rage_comic_details.xml. After changing it to the same as it was in the tutorial everything works now. Thank you!!!

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!