0

When I change my targetSDK to greater than 22, the compiler does not allow to use permissions directly. The permissions have to be provided by user for which I have to use below code :

if(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED) {

        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                MY_PERMISSSIONS_REQUEST_FINE_LOCATION);

 }

But I keep getting the below error

Didn't find class "android.support.v4.content.ContextCompat"

I have added all the required files for ContextCompat and ActivityCompat but I keep getting this error every time. Here is my build.gradle

[EDIT] Adding the whole gradle file

apply plugin: 'com.android.library'

    android {
        compileSdkVersion 25
        buildToolsVersion "25.0.2"

        defaultConfig {
            minSdkVersion 15
            targetSdkVersion 25
            versionCode 1
            versionName "1.0"

            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile 'com.android.support:appcompat-v7:25.2.0'
        compile files('libs/classes.jar')
        compile 'com.android.support:support-v4:25.2.0'
    }

    //task to delete the old jar
    task deleteOldJar(type: Delete) {
        delete '/Users/kushagragupta/Desktop/Kushagra/STURFEE/Sturfee.Unity.Mobile.IMUGPSTest/Assets/AndroidPlugin.jar'
    }

    //task to export contents as jar
    task exportJar(type: Copy) {
        from('build/intermediates/bundles/release/')
        into('/Users/kushagragupta/Desktop/Kushagra/STURFEE/Sturfee.Unity.Mobile.IMUGPSTest/Assets/')
        include('classes.jar')
        ///Rename the jar
        rename('classes.jar', 'AndroidPlugin.jar')
    }

    exportJar.dependsOn(deleteOldJar, build)

I could literally see these libraries in Android Studio enter image description here

I've been stuck on this since last 2 days and have no idea what else can be done to fix this.

3
  • How about using ActivityCompat for checking the permissions, does it throw same error (ActivityCompat is a direct subclass)? developer.android.com/reference/android/support/v4/app/… Commented Mar 10, 2017 at 0:21
  • Show the entire app gradle file Commented Mar 10, 2017 at 0:36
  • edited @DanielNugent Commented Mar 10, 2017 at 7:14

1 Answer 1

2

What I found in regards to support-v4-25.2.0 is that the .aar that is shipped with the Android SDK looks more or less empty, only 2KB in size. Looking further I saw that all the .aar files back to 24.1.1 are only 2KB in size. enter image description here

I could solve it using version 24.1.1.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.