• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Spring Android Rest Template stops working when I upgrade Android version  RSS feed

 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi ,
I'm trying to get an application that ran on Android 5 ( target api 22) to run on Android 7 (target api 25) .
I'm running into security permissions issues for an application that depends on the Spring Rest Framework for Android .
I need to upgrade the target version to use "ActivityCompat.requestPermissions..."
When I change the target version from 22 to 25 in Android Studio I get a lot of errors "Can't resolve symbol ..." from the Spring based code.

Hopefully someone can help .
Thanks.

Here is my Gradle (Module) file :


Here is my manifest File:
 
Saloon Keeper
Posts: 1844
80
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Paul,

this is common due to the fact that the Android permissions model have changed with newer versions of Android.

Android API Doc wrote:On all versions of Android, your app needs to declare both the normal and the dangerous permissions it needs in its app manifest, as described in Declaring Permissions.
However, the effect of that declaration is different depending on the system version and your app's target SDK level:

If the device is running Android 5.1 or lower, or your app's target SDK is 22 or lower:
   - If you list a dangerous permission in your manifest, the user has to grant the permission when they install the app;
     if they do not grant the permission, the system does not install the app at all.
If the device is running Android 6.0 or higher, and your app's target SDK is 23 or higher:
   - The app has to list the permissions in the manifest, and it must request each dangerous permission it needs while the app is running.
     The user can grant or deny each permission, and the app can continue to run with limited capabilities even if the user denies a permission request.
Note: Beginning with Android 6.0 (API level 23), users can revoke permissions from any app at any time, even if the app targets a lower API level.
You should test your app to verify that it behaves properly when it's missing a needed permission, regardless of what API level your app targets.

You can read more about this here https://developer.android.com/training/permissions/requesting.html

You may want to take a step back and go over the tutorials located here https://developer.android.com/training/permissions/index.html
 
paul nisset
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Peter.

I get the idea with Permissions requirements.

The problem seems to be the spring framework doesn't work with a newer api that I am using to manage permissions.
If I remove "appcompat-v7" below the app compiles and runs but can't use any of the functionality that requires permissions .
That makes sense.
If I do include the "appcompat-v7 " library , I get the error described below "Can't resolve symbol ..." from the Spring Rest Template code.
It seems like the appcompat-v7 library is preventing the Spring Rest library from loading.

This is the relevant code:





This is where I get the "can't resolve symbol" message.
 
Pete Letkeman
Saloon Keeper
Posts: 1844
80
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just double checking. which guide are were using this as a base for your project https://spring.io/guides/gs/consuming-rest-android/ or http://projects.spring.io/spring-android/ ?
I suspect that you are using https://spring.io/guides/gs/consuming-rest-android/ but I'm not 100% sure.

I do see a couple of things that you may want to change, which could help out.

Concern #1: The plus sign
Instead oftryOr some other number which is close to your build tools version which you have downloaded to your local system.
Doing this will force your code to use the same version all the way through the project's life and it will speed up compile time.
Right now every time you compile the first thing that happens is Gradle resolves the "+". Then Gradle checks and downloads that version of the library if not there.
Finally Gradle includes that library. If you force a version then Gradle will only use that version once and the compile times will be consistent and faster.
Not only that you will be using the same library so you won't be surprised if a new version comes out and something is deprecated.

Concern #2: Repos
Currently you have However I suspect that you will get better results if you add the following lines to give you thisI'm not too sure if the order of the lines in the repositories matter, so may want to change the order for the two maven entries.
By using the Google these repositories you can be sure that you have the correct controls and libraries.

paul nisset wrote:It seems like the appcompat-v7 library is preventing the Spring Rest library from loading.


It is not impossible (not likely) for the order of these libraries to matter. Have you tried changing the order so instead ofyou have

Given that you currently do have a working App, what if you create a small app which only tries to do this one REST thing. That way you could isolate the Internet permission part and remove the unneeded noise.
It's totally possible that you have something else in your App, which may be totally unrelated, that is causing the problem.

Have you tried to use an older version of the Android Rest Template? 2.0.0.M3 may already be a tested library which could be a year or two old, but there could be something in that library, which may be the problem.
2.0.0.M3  is currently listed as "PRE", but 2.0.0 is older and listed as a Snapshot. Perhaps it does a better job.
 
paul nisset
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter,
Thanks for the tips.
Concern 1 is an especially good point.

I did try reversing the compile lines in Concern 2.
I've had that issue before and reversing the lines fixed it  but not in this case.

I'll try adding the google repos.

The application worked on an external device previously before I went to a later Android target version .
Creating a new app from scratch that uses just the Spring Rest API at a higher Android  version level sounds like a good strategy.

thank you,
Paul
 
Pete Letkeman
Saloon Keeper
Posts: 1844
80
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

paul nisset wrote:Thanks for the tips.
Concern 1 is an especially good point.

You are welcome. Just trying to help out a fellow programmer.

Please post back once you have tried out creating a separate simple program which is able to create a HTTP call.
 
paul nisset
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

So, for anyone interested, I finally got this fixed.

It turns out HttpClient is no longer supported from SDK 23 onward.

You are supposed to use "URLConnection" now.

Adding the following fixed the problem:


I got the solution from here:
https://stackoverflow.com/questions/32153318/httpclient-wont-import-in-android-studioStack overflow solution
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!