java.lang.NoSuchMethodError: No static method getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)

AndroidAndroid Studio-3.0Android Gradle-3.0

Android Problem Overview


After I updated my Android Studio to 3.0 I am getting No static method getFont() error. The project on which I am working is on github, https://github.com/ik024/GithubBrowser

// Top-level build file where you can add configuration options common 
to all sub-projects/modules.

buildscript {
repositories {
    jcenter()
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0'
    classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-SNAPSHOT'
}
}

allprojects {
repositories {
    jcenter()
    maven { url 'https://maven.google.com' }
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}

ext{
    arch_version = "1.0.0-alpha9"
    support_version = "26.0.2"
    dagger_version = "2.11"
    junit_version = "4.12"
    espresso_version = "2.2.2"
    retrofit_version = "2.3.0"
    mockwebserver_version = "3.8.0"
    apache_commons_version = "2.5"
    mockito_version = "1.10.19"
    constraint_layout_version = "1.0.2"
    timber_version = "4.5.1"
    butterknife_version = "9.0.0-SNAPSHOT"
    rxbinding_version = "2.0.0"
    retrofit_version = "2.3.0"
    okhttp_version = "3.6.0"
    rxjava2_adapter_version = "1.0.0"
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

app gradle

apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.butterknife'

android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
    applicationId "com.ik.githubbrowser"
    minSdkVersion 17
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
packagingOptions {
    exclude 'META-INF/rxjava.properties'
}

testOptions {
    unitTests.returnDefaultValues = true
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

compile "com.android.support.constraint:constraint-layout:$constraint_layout_version"

compile "com.android.support:appcompat-v7:$support_version"
compile "com.android.support:recyclerview-v7:$support_version"
compile "com.android.support:cardview-v7:$support_version"
compile "com.android.support:design:$support_version"
compile "com.android.support:support-v4:$support_version"

compile "android.arch.persistence.room:runtime:$arch_version"
compile "android.arch.lifecycle:runtime:$arch_version"
compile "android.arch.lifecycle:extensions:$arch_version"
compile "android.arch.persistence.room:rxjava2:$arch_version"

compile "com.squareup.retrofit2:retrofit:$retrofit_version"
compile "com.squareup.retrofit2:converter-gson:$retrofit_version"
compile "com.squareup.retrofit2:adapter-rxjava:$retrofit_version"
compile "com.jakewharton.retrofit:retrofit2-rxjava2-adapter:$rxjava2_adapter_version"

compile "com.squareup.okhttp3:okhttp:$okhttp_version"
compile "com.squareup.okhttp3:logging-interceptor:$okhttp_version"


compile "com.jakewharton.timber:timber:$timber_version"
compile "com.jakewharton:butterknife:$butterknife_version"
compile "com.jakewharton.rxbinding2:rxbinding:$rxbinding_version"

compile "com.google.dagger:dagger:$dagger_version"
compile "com.google.dagger:dagger-android:$dagger_version"
compile "com.google.dagger:dagger-android-support:$dagger_version"

testCompile "junit:junit:$junit_version"
testCompile "com.squareup.okhttp3:mockwebserver:$mockwebserver_version"
testCompile("android.arch.core:core-testing:$arch_version", {
    exclude group: 'com.android.support', module: 'support-compat'
    exclude group: 'com.android.support', module: 'support-annotations'
    exclude group: 'com.android.support', module: 'support-core-utils'
})

androidTestCompile "com.android.support:appcompat-v7:$support_version", {
    exclude group: 'com.android.support', module: 'support-annotations'
    exclude group: 'com.android.support', module: 'support-fragment'
    exclude group: 'com.android.support', module: 'support-core-ui'
}

androidTestCompile "com.android.support:recyclerview-v7:$support_version", {
    exclude group: 'com.android.support', module: 'support-annotations'
    exclude group: 'com.android.support', module: 'support-fragment'
    exclude group: 'com.android.support', module: 'support-core-ui'
}

androidTestCompile "com.android.support:support-v4:$support_version", {
    exclude group: 'com.android.support', module: 'support-annotations'
    exclude group: 'com.android.support', module: 'support-fragment'
    exclude group: 'com.android.support', module: 'support-core-ui'
}

androidTestCompile "com.android.support:design:$support_version", {
    exclude group: 'com.android.support', module: 'support-annotations'
    exclude group: 'com.android.support', module: 'support-fragment'
    exclude group: 'com.android.support', module: 'support-core-ui'
}

androidTestCompile("com.android.support.test.espresso:espresso-core:$espresso_version", {
    exclude group: 'com.android.support', module: 'support-annotations'
    exclude group: 'com.google.code.findbugs', module: 'jsr305'
})

androidTestCompile("com.android.support.test.espresso:espresso-contrib:$espresso_version", {
    exclude group: 'com.android.support', module: 'support-annotations'
    exclude group: 'com.google.code.findbugs', module: 'jsr305'
    exclude group: 'com.android.support', module: 'support-fragment'
    exclude group: 'com.android.support', module: 'support-core-ui'
})

androidTestCompile("android.arch.core:core-testing:$arch_version", {
    exclude group: 'com.android.support', module: 'support-annotations'
})

androidTestCompile 'org.mockito:mockito-android:2.7.15', {
    exclude group: 'com.android.support', module: 'support-annotations'
}

annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version"
annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"
annotationProcessor "android.arch.persistence.room:compiler:$arch_version"
annotationProcessor "android.arch.lifecycle:compiler:$arch_version"
annotationProcessor "com.jakewharton:butterknife-compiler:$butterknife_version"


compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.0.2'

}

Error:

> FATAL EXCEPTION: main Process: com.ik.githubbrowser, PID: 4248 > java.lang.NoSuchMethodError: No static method > getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)Landroid/graphics/Typeface; > in class Landroid/support/v4/content/res/ResourcesCompat; or its super > classes (declaration of > 'android.support.v4.content.res.ResourcesCompat' appears in > /data/app/com.ik.githubbrowser-YvwoGrxR8QaUEZ3IEqFVLQ==/split_lib_dependencies_apk.apk) > at > android.support.v7.widget.TintTypedArray.getFont(TintTypedArray.java:119) > at > android.support.v7.widget.AppCompatTextHelper.updateTypefaceAndStyle(AppCompatTextHelper.java:208) > at > android.support.v7.widget.AppCompatTextHelper.loadFromAttributes(AppCompatTextHelper.java:110) > at > android.support.v7.widget.AppCompatTextHelperV17.loadFromAttributes(AppCompatTextHelperV17.java:38) > at > android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:81) > at > android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:71) > at > android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:67) > at android.support.v7.widget.Toolbar.setTitle(Toolbar.java:753) at > android.support.v7.widget.ToolbarWidgetWrapper.setTitleInt(ToolbarWidgetWrapper.java:261) > at > android.support.v7.widget.ToolbarWidgetWrapper.setWindowTitle(ToolbarWidgetWrapper.java:243) > at > android.support.v7.widget.ActionBarOverlayLayout.setWindowTitle(ActionBarOverlayLayout.java:621) > at > android.support.v7.app.AppCompatDelegateImplV9.onTitleChanged(AppCompatDelegateImplV9.java:631) > at > android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:328) > at > android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) > at > android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) > at > com.ik.githubbrowser.ui.search_user.SearchUserActivity.onCreate(SearchUserActivity.java:49) > at android.app.Activity.performCreate(Activity.java:6975) at > android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213) > at > android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770) > at > android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) > at android.app.ActivityThread.-wrap11(Unknown Source:0) at > android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) > at android.os.Handler.dispatchMessage(Handler.java:105) at > android.os.Looper.loop(Looper.java:164) at > android.app.ActivityThread.main(ActivityThread.java:6541) at > java.lang.reflect.Method.invoke(Native Method) at > com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) > at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

Android Solutions


Solution 1 - Android

Fix res/values/styles.xml and Manifest.xml like so:This solution is tested and don't forget to clean and build :

1.Manifest.xml

change the theme of HomeActivity to :

        <activity
        android:name=".ui.home.HomeActivity"
        android:theme="@style/Base.Theme.AppCompat.Light" />
    <activity android:name=".BaseActivity"></activity>

2. res/values/styles.xml Make all your themes preceeded with Base :styles.xml will be like this :

<resources>

<!-- Base application theme. -->
<!--<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">-->

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">


<!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar" parent="Base.Theme.AppCompat.Light">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="Base.ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="Base.ThemeOverlay.AppCompat.Light" />

Detailed explanation as requested: Theme.AppCompat.Light.DarkActionBar is a subclass of the superclass Base anyway. Ctrl+click (Android Studio) on it and you will be taken to the source:

<style name="Theme.AppCompat.Light.DarkActionBar" parent="Base.Theme.AppCompat.Light.DarkActionBar" />

3. GithubBrowser-Master.gradle

make support_version = "27.0.0" and not support_version = "26.0.2

4.app.gradle :

compileSdkVersion 27
    buildToolsVersion '27.0.0'

and not

   compileSdkVersion 26
buildToolsVersion '26.0.2'

Solution 2 - Android

Change the build tools version in app's gradle under android section:

buildToolsVersion "27.0.3"

Also add below dependencies to your app build.gradle

dependencies {
compile 'com.android.support:appcompat-v7:27.0.0'
compile 'com.android.support:design:27.0.0'
compile 'com.android.support:support-v4:27.0.0'
compile 'com.android.support:support-v13:27.0.0'
}

Sync gradle changes and rebuild the project.

Solution 3 - Android

In my case, I was using Android-KTX: implementation 'androidx.core:core-ktx:0.1' in Kotlin project, and that was the cause of the error. I just removed it from build.gradle as a dependency.

Solution 4 - Android

I faced similar issue, was able to resolved it by setting application gradle file.

**Change your compile sdk version to 27 and buildToolsVersion to 27.0.3 in build.gradle file under android **

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"

Add 27.1.1 version support libraries.

implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1' 
implementation 'com.android.support:appcompat-v7:27.1.1'

and then sync project. Run the app.

Solution 5 - Android

Make sure your comileSdkVersion and targetSdkVersion should be same :

Comile and SDK Versions

and also update your dependencies to the latest version and sync the project and run it. it's helped me to resolve the issue.

Dependencies

Solution 6 - Android

I had same problem, fixed with just change the appcompat and design and recyclerview to these valeus:

implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:design:27.0.2'
implementation 'com.android.support:recyclerview-v7:27.0.2'

and sync gradle again

Solution 7 - Android

The compileSdkVersion 26 sometimes gives this error. To resolve it,please upgrade the compileSdkVersion and targetSdkVersion to 27 in app.gradle file. Also change the corresponding dependencies in dependencies section. You don't need to specify buildToolsVersion for this.

Solution 8 - Android

The version of all dependencies should be same with compileSdkVersion.

below code in build.gradle(module) work for me.

android {
    compileSdkVersion 26
    // ...
}

dependencies {
    implementation 'com.android.support:appcompat-v7:26.0.2'
    implementation 'com.android.support:recyclerview-v7:26.0.2'
    implementation 'com.android.support:cardview-v7:26.0.2'
    // ...
}

Solution 9 - Android

In My case, This issue was coming because of the combination of Glide and Appcompat library (Versions are not supporting each other).

So below is what worked for me(In App level build.gradle)-

implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.github.bumptech.glide:glide:4.8.0'
 

Hope It will help somebody.

Solution 10 - Android

Just change activity theme in manifest to any one like:

android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"

Solution 11 - Android

The solution is really simple..u just need to change build tool to 27.0.2 And all supports library version to 27.0.2 Bingo..error solved

Solution 12 - Android

I tried to find an answer in this question but in my case it was my configuration:

android {
    compileSdkVersion 26
     defaultConfig {
        applicationId "com.jorgesys.gifanimated"
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

To solve this issue i just add the definition of the buildToolsVersion and it works!

   buildToolsVersion "26.0.2"

Probably is necessary that our build tools version is the same as the support libraries version.

Solution 13 - Android

For me the problem was caused by one of my app dependencies using a higher version of Android Support Library than the one I was depending on. If you don't want to update to latest version just yet, you can force the use of your version of the library.

To see which dependency uses newer version, you can run: ./gradlew app:dependencies and look for com.android.support occurences that declare a different version than you are using. For example:

./gradlew app:dependencies \
  | grep com.android.support \
  | grep -vE "constraint-layout|support.test|multidex|->|26.1.0"

should show you dependencies that use a version different than 26.1.0. (Android Studio should also give you an example dependency conflict in a tooltip on some com.support.android dependencies listed in your build.gradle)

In my case it was com.android.support:support-compat:27.1.0 (and support-annotations), so run:

./gradlew app:dependencyInsight \
  --configuration <YOUR_BUILD_VARIANT>CompileClasspath
  --dependency support-compat

To see what library depends on 27.1.0 version of support-compat. (Replace <YOUR_BUILD_VARIANT> with one of your build variants, e.g. debug).

In my case it was:

com.android.support:support-compat:27.1.0 (conflict resolution)
\--- androidx.core:core-ktx:0.3
     \--- devDebugCompileClasspath

and replacing:

implementation 'androidx.core:core-ktx:0.3'

with:

implementation ('androidx.core:core-ktx:0.3') {
    exclude module: 'support-annotations'
    exclude module: 'support-compat'
}

fixed the issue for me.

Solution 14 - Android

Here is my answer to it, it maybe different scenario but i got this error.

I was creating a music player app and i had added the following library in my app gradle file.

implementation 'com.google.android.exoplayer:exoplayer:2.8.0'

I was following this tutorial for integrating ExoPlayer in my app. I changed this library version from 2.8.0 to 2.6.0 and it worked fine.

I hope this helps someone.

Solution 15 - Android

Whenever this error occurs just update buildtools and support dependencies to newer version.It will fix the issue. Keep in mind that all support dependencies should be same version

buildToolsVersion '28.0.2'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'

Solution 16 - Android

upload gradle!

classpath 'com.android.tools.build:gradle:3.3.1'

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionik024View Question on Stackoverflow
Solution 1 - AndroidNawrezView Answer on Stackoverflow
Solution 2 - AndroidMaysam RView Answer on Stackoverflow
Solution 3 - AndroidGentView Answer on Stackoverflow
Solution 4 - Androidmehmoodnisar125View Answer on Stackoverflow
Solution 5 - AndroidPawar ShahView Answer on Stackoverflow
Solution 6 - AndroidMohammadLView Answer on Stackoverflow
Solution 7 - AndroidDNBView Answer on Stackoverflow
Solution 8 - AndroidAhuraMazdaView Answer on Stackoverflow
Solution 9 - AndroidB.shrutiView Answer on Stackoverflow
Solution 10 - AndroidKhalid AliView Answer on Stackoverflow
Solution 11 - AndroidMihir JoshiView Answer on Stackoverflow
Solution 12 - AndroidJorgesysView Answer on Stackoverflow
Solution 13 - AndroidarekolekView Answer on Stackoverflow
Solution 14 - AndroidHarry .NaeemView Answer on Stackoverflow
Solution 15 - AndroidJackView Answer on Stackoverflow
Solution 16 - AndroidFredy sanchez .mView Answer on Stackoverflow