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 .
Here is my Gradle (Module) file :
Here is my manifest File:
this is common due to the fact that the Android permissions model have changed with newer versions of Android.
You can read more about this here https://developer.android.com/training/permissions/requesting.html
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 may want to take a step back and go over the tutorials located here https://developer.android.com/training/permissions/index.html
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.
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.
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.
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