0

Please help, I try to update android targetSdkVersion to version 33.

my build.gradle:

compileSdkVersion 19
buildToolsVersion '26.0.2'
defaultConfig {
  minSdkVersion 14
  targetSdkVersion 19
}

AndroidManifest:

android:minSdkVersion="14"
android:targetSdkVersion="19"
uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" 
uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" 

After I update the targetSdkVersion(compileSdkVersion and buildToolsVersion) to 33(in build.gradle and AndroidManifest.xml) I get this exception:

`java.lang.RuntimeException: Unable to start activity ComponentInfo{activity.MainActivity}: 
java.lang.SecurityException: uid 10159 does not have android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3645)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.SecurityException: uid 10159 does not have android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION.`

As a note:

  • flow when starting the app with targetSdkVersion 19 on android 13: the permission screen appear after that the warning popup that I am using an old version of android, after that log in screen
  • flow after I change the targetSdkVersion to 33 on android 13: the log in screen is the first screen, not showing the permission screen, I enter the log in credentials and after that throw the exception, I am not sure why not asking for permission first

Thanks

Exception is thrown from line: Location gpsLocation = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

public abstract class MyActivity extends AnaliticsActivity implements OnRefreshListener {
    ..........
    private GPSManager gpsManager;
    private Context mContext;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        mContext = this;

        initActivity();
        initHelpers();
        initActionBar();
    }
    
    private void initActivity() {

        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    private void initHelpers() {
        gpsManager = new GPSManager(getApplicationContext());
...
    }
    ........
}

public class GPSManager implements LocationListener {
    ...
    public GPSManager(Context context,) {
        // reference to the system Location Manager
        mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        Location gpsLocation = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        .....
    }
    ....
}
api
  • 1
  • 1

1 Answers1

0

Starting with Android 6 you need to request permissions at runtime. I can't find the details on the compatibility mechanisms, but I suspect that when your targetSdkVersion was below 23 (which is Android 6) it was running in compatibility mode and requesting all the permissions at the start just like on the old versions. Now that you updated it past 23 you basically said "I expect my app to work correctly on api 33" (see this Q&A), which includes rntime permissions.

Sergei Kozelko
  • 691
  • 4
  • 17