0

I checked the question : setGroup() is undefined for the type NotificationCompat.Builder?

But it did not help.

I have a project which I imported from eclipse. On running I get error:

error: cannot find symbol .setGroup("group") ^ symbol: method setGroup(String)

On googling I find people suggesting to update android-support library.While importing the project I used the option to retain the jar files from the project and not convert them to dependencies in android studio.Hence I presume the same support jar file is being used from the libs folder of project. The same code runs fine on eclipse. On checking I see the support jar file is exactly same on both projects. Then how come one method is being undefined in project but visible on another. Is it possible that Android Studio is replacing the support jar file from its own jar file?

Code:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setContentTitle(text)
                .setContentText(text)
                .setStyle(inboxStyle)
                .setNumber(stack.size())
                .setSmallIcon(R.drawable.launcher)
                .setGroup("group")
                .setGroupSummary(true);

EDIT:

I changed the dependency as per below suggestion to use dynamic support library instead of jar. But still see the same error, My build.gradle looks like this now.

 compile project(':facebookSDK')
    compile project(':googleplayservices_lib')
    compile 'com.android.support:support-v13:25.1.0'
    compile files('libs/activation.jar')
    compile files('libs/additionnal.jar')
  //  compile files('libs/android-support-v13.jar')
    compile files('libs/eat.jar')
    compile files('libs/gcm-server-1.0.2.jar')
    compile files('libs/google-api-client-1.10.3-beta.jar')
    compile files('libs/google-api-client-android2-1.10.3-beta.jar')
    compile files('libs/google-http-client-1.10.3-beta.jar')
    compile files('libs/google-http-client-android2-1.10.3-beta.jar')
    compile files('libs/google-oauth-client-1.10.1-beta.jar')
    compile files('libs/gson-2.1.jar')
    compile files('libs/jackson-core-asl-1.9.4.jar')
    compile files('libs/json-simple-1.1.1.jar')
    compile files('libs/jsr305-1.3.9.jar')
    compile files('libs/mail.jar')

EDIT2:

Based on below answer I added v4 library alongside v13 but still the error persists. Any more clues? My current dependencies look like

dependencies {
    compile project(':facebookSDK')
    compile project(':googleplayservices_lib')
    compile files('libs/activation.jar')
    compile files('libs/additionnal.jar')
    compile files('libs/android-support-v13.jar')
    compile 'com.android.support:support-v4:25.1.0'
    compile files('libs/eat.jar')
    compile files('libs/gcm-server-1.0.2.jar')
    compile files('libs/google-api-client-1.10.3-beta.jar')
    compile files('libs/google-api-client-android2-1.10.3-beta.jar')
    compile files('libs/google-http-client-1.10.3-beta.jar')
    compile files('libs/google-http-client-android2-1.10.3-beta.jar')
    compile files('libs/google-oauth-client-1.10.1-beta.jar')
    compile files('libs/gson-2.1.jar')
    compile files('libs/jackson-core-asl-1.9.4.jar')
    compile files('libs/json-simple-1.1.1.jar')
    compile files('libs/jsr305-1.3.9.jar')
    compile files('libs/mail.jar')
}

edit4:

I also tried this combination, nothing seems to be working :(

 // compile files('libs/android-support-v13.jar')
    compile 'com.android.support:support-v13:25.1.0'
    compile 'com.android.support:support-v4:25.1.0'

I also noticed one thing, even if I remove v4 from dependencies , I dont get a compilation error while import NotificationCompat classes. How come this be possible? Could it be that it is picking up some other copy of library from some other module?

EDIT: 5

Based on my discussions here with Martin I wanted to share some insights which would help us all . As per Android Studio it picks up the first library (or any library, I am not sure) from any modules and starts using it in your module. This is wrong at so many levels! I will explain you how, Please correct me at any place as this would help us all.

  1. Causes licensing issue: As in here , I am using a vendor library module in project (Facebbok SDK in this case) , it is using some libraries for its own purpose (v4 lib in this case). Now as a developer I do not know what are the licensing terms in which my vendor library is using that third party library. But never the less I am able to use the same library in my module, EVEN WHEN I HAVE NOT DEFINED IT IN MY OWN DEPENDENCIES, breaching licensing agreement.

  2. Causes confusion: Imagine this, I am not even aware that I am using a function from a third party library. As I see that I have not defined this library my build.gradle. But internally I might have used a function which had come up from a random library. The editor will of course silent import the classes for that method and the developer will not have any clue as to which library it called. This is exactly what happened here , as I was not aware that this method was coming from a v4 library as I had not imported it in my build.gradle file!

  3. Unable to update to latest version: This is yet another problem that I faced here. After the below discussion I am aware that AS has used facebooks library, but now I am unable to update the library for my use. Why? because facebook has used the old library
    at the time of developement. I cannot update facebook's library (technically I can but I should not ) and I dont want to update faceboook sdk due to some other constraints. Also, no reason to update facbook sdk as all my current needs are being fulfilled from this sdk.

All this just because AS thinks it knows better than me as to which library I should be using in my own project.

Community
  • 1
  • 1
Utsav Gupta
  • 3,785
  • 5
  • 30
  • 52
  • Which support-library version are you using? Remember that setting group method was added to NotificationCompat very recently and if you use an old version of the library it could be not present. – Martin Revert Dec 24 '16 at 16:10
  • @MartinRevert How do i check the version of the support jar file? – Utsav Gupta Dec 24 '16 at 16:12
  • Why are you not using Gradle? Stop using JARs and Eclipse (ADT Tools for Eclipse are deprecated and unsupported), and use Android Studio+Gradle. You need to add a recent support v4 as a dependency in Android Studio in this format `compile 'com.android.support:support-v4:25.1.0'` Android Studio will help you to maintain your support libraries alerting you when they aren't updated. – Martin Revert Dec 24 '16 at 16:22
  • @MartinRevert Thanks for suggestion, also can you tel me where you pick this string from 'com.android.support:...' I mean the documentation. Also what would be a corresponding string for support v13 lib? – Utsav Gupta Dec 25 '16 at 04:42
  • 1
    Facebook has a very old v4 jar in it which doesn't have setGroup() implemented (it is a 3 years old version). I've think that all the project is using that. I don't know if there are another inconsistencies, but Facebook is one for sure. Remove that from Facebook build.gradle and let your build.gradle support v4 took the Facebook job Check this: https://github.com/facebook/facebook-android-sdk/commit/13af7a53e3201a139f446bb253bde71dad2e5d2d – Martin Revert Dec 25 '16 at 06:31
  • @MartinRevert You are right! I figured that out just now, now the question is how do I force android studio to use my v4 lib than facebooks . I dont want to change facebook's v4 lib as that would be technically incorrect. And I dont want to update facebook SDk as of now for the risk of breaking other things. hence the only option is to force android studio to use my latest v4 library. Unfortunately its not happening its still clinging on to fb's lib even after defining it in my own project. Any help there? – Utsav Gupta Dec 25 '16 at 06:38
  • Moving to a modern v4 support is the correct move, If something breaks is Facebook SDK for Android team technical debt, not yours. Maybe you can test if upgrading has some impact, and maybe push a request to Facebook team to upgrade the support library. – Martin Revert Dec 25 '16 at 06:42
  • But as I mentioned, I am unable to use 'my own v4 lib in my own project' just because there is an old version of facebook v4 lib. This is so wrong!. I want to tell Android Studio somehow to use my latest v4 lib ..how do i do that. Even after defining it as a dependency, AS continues to use facebook's v4 lib. Technically I should not be bothered about what my vendor libraries are using. – Utsav Gupta Dec 25 '16 at 06:48
  • Oh, the way to ensure that your v4 is working is to remove all other references to old v4 in other associated projects. Thsi way, Gradle didn't compile the first v4 of many, but just one and valid v4. – Martin Revert Dec 25 '16 at 06:48
  • Based on your suggestion I removed the dependency of v4 from facebook sdk, but then facebook started breaking at the time of building. – Utsav Gupta Dec 25 '16 at 06:52
  • So you hit a definitive constraint: Ask Facebook team to upgrade support v4. It doesn't need to be 25.1.0, if i not recall badly setGroup and setGroupSummary were added in 20.0.0 version, so they only need to bump one version to offer you that possibility. One last lucky try: Can you try to move Facebook SDK dependency to bottom and your support v4 up? Add the old v4 reference in Facebook too. Maybe we can fool Gradle making choose that. Just a guess, never tried myself if that order has some impact. – Martin Revert Dec 25 '16 at 06:56
  • I dont think its a facebook issue, everyone is free to use their own versions of libraries. I am surprised that Android Studio picks up libraries from other modules and that without informing you! And above all does not let you change it !! I would suggest it to give developers a chance to choose libraries for THEIR OWN PROJECT, Rather than playing a big brother there. Or learn it from eclipse , eclipse tells you that it has found multiple versions and it is going to use the latest of all. – Utsav Gupta Dec 25 '16 at 07:02
  • Well, that's a matter of opinion. Profesionally I never made a library that forces users to use older Google libraries because things easily breaks like in this case. FBK team need to keep Google's pace if they want to use offcial support libraries. If they don't do that you must to understand that having several different v4 libraries with nearly the same classes is redundant but also may break things. – Martin Revert Dec 25 '16 at 07:10
  • But anyways, you also have options; a) Don't use groups on your notification until Facebook upgrade things. b) Don't use NotificationCompat.Builder and use Notification.Builder and API from 20 and up c) Fix yourself the Facebook SDK bugs with the new v4 d)Ask FBK team to upgrade the old library and code (and sit and wait). – Martin Revert Dec 25 '16 at 07:11
  • Thanks for suggesting the alternatives , I am hoping it to be sarcastic :), But also thanks for your wonderful insights on support release notes, and Merry Christmas! – Utsav Gupta Dec 25 '16 at 07:21
  • No Ustav, they are not sarcastic, that suggestions are all your options that you can start right now in order to move on. Also I suggest that you accept as valid my response because the original question was about the absence of setGroup method and that was cleared from the beginning. The FBK running behind with older libraries is another problem and it requires its own solution which exceeds your original question. Happy Christmas to you too!!! – Martin Revert Dec 25 '16 at 07:29
  • I agree to your last part as the valid answer but dont agree to change my functionality to appease Android Studio. Few things are final: a) I will not update facebook library as all my current needs are being fulfilled by the current FB library and fb library is not giving me any troubles b) I should not be changing the method calls as the document says these methods are perfectly fine to be called. c) there are no bugs to be fixed on FB here :). I have marked your answer as correct for pointing out that v13 is not the correct library but v4 is. Thanks again. – Utsav Gupta Dec 25 '16 at 10:59
  • Is not an Android Studio problem. In the old Eclipse you cannot even compile 2 libraries with same name and different codebases. Always was the same: If you need to include a library several times on your project it needs to be the same versión and release on all occurrencies. It is a Fbk SDK problem, their code is based on obsolete code, so they are forcing you to use V4 19.x all along your project when you need V4 20.x and up. Also they are using + wildcard versioning on Gradle which is basically a bad practice. Don't get mad with me, I'm just trying to help you understand. – Martin Revert Dec 25 '16 at 19:25

1 Answers1

1

Well, as per your EDIT you didn't follow my complete suggestion so the error is more obvious now: NotificationCompat.Builder is not implemented in support v13.app.*

You need to use a modern support v4 release or you can use support v7 which extends from v4, this depends on your present or future needs and other libraries dependencies. But using one of them must make setGroup() available for you, because both libraries offer the NotificationCompat.Bulder helper class.

https://developer.android.com/reference/android/support/v7/app/NotificationCompat.html

Regardling precise version numbers, the official docs that allow you to follow up releases (and their respective changes) are here:

https://developer.android.com/topic/libraries/support-library/revisions.html

But in my experience, it is better to check periodically your build.gradle dependencies, because every time you download and upgrade the SDK packages from Google, Android Studio will highlight your old Google dependencies offering the new number of version to upgrade.

Martin Revert
  • 3,242
  • 2
  • 30
  • 33
  • AFAIK if 'you want to support android v>13 use support v13 lib if you want to support android v>4 use v4 lib' by that logic shouldnt both the libs be exactly the same, except for the backward compatibility? How can one lib does not have one method while other one has ? – Utsav Gupta Dec 25 '16 at 05:29
  • 1
    No, the Vx versions are not incremental, they are complementary and only in some special cases like NotificationCompat you can discard v4 and use v7 if you don't need too much older retrocompatibility. Also in many cases they are used together. Support v13 only offer these classes in the app package https://developer.android.com/reference/android/support/v13/app/package-summary.html – Martin Revert Dec 25 '16 at 05:37