Kushagra
Kushagra

Reputation: 93

Didn't find class "android.support.v4.content.ContextCompat" even after adding all the libraries

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.

Upvotes: 0

Views: 2972

Answers (1)

Thor_Bux
Thor_Bux

Reputation: 1157

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.

Upvotes: 2

Related Questions