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

16

60

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)

Solar answered 4/11, 2017 at 18:13 Comment(0)
T
76

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'
Tella answered 5/11, 2017 at 20:9 Comment(10)
Thanks it solved for me. Does it mean buildToolVersion 26.0.2 has a bug ?Solar
I think so ! I tried with 26.0.2 but it doesn't workTella
Thanks! I used 27.0.2 instead, without any other changes in res/values/styles.xml and Manifest.xml, the problem just resolved.Buttock
@Buttock : when I ansewered this questionlast build tools was 27.0.1 and it doesn't work for me, I think it was a fix done in 27.0.2 and that's good :)Tella
It Works for meEarpiercing
@Tella I did an Edit > Find > Find in Path search but did not find a GithubBrowser-Master.gradle despite my project using Github. Although the problem was solved without this step, is this something I should be concerned about?Wolff
in my case I found that problem occur because I let my activity extends AppCompatActivity. Try to change AppCompatActivity to Activity and it worksMuddleheaded
@Solar No, this is not a bug. This occurs because at least one of your libraries has dependency on support library as well, where its version is different with your support library version stated in app's build.gradle. Different version of support library caused crash because some methods may not exist in an older or newer version of support library, but your project can only compile one of them.Statutory
OMG Android is so complicated!Brigittebriley
I had to modify the res/values/styles.xml to after doing this to make it work ok. I added "AppTheme.NoActionBar", "AppTheme.AppBarOverlay", and "AppTheme.PopupOverlay" styles taken from a simple new project.Badenpowell
U
16

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.

Unkempt answered 24/12, 2017 at 8:59 Comment(1)
This worked for me in Android studio 3.1 by making compileSdkVersion 27Radu
R
7

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.

Rumen answered 20/2, 2018 at 12:25 Comment(0)
A
5

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.

Ashore answered 3/8, 2018 at 11:15 Comment(1)
This worked for me. No need to make changes to the manifest or styles xml files.Mlle
B
4

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

Boudicca answered 30/1, 2018 at 3:16 Comment(0)
C
4

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

Crenshaw answered 27/2, 2018 at 7:12 Comment(0)
L
2

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.

Loads answered 6/2, 2018 at 5:36 Comment(0)
A
2

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'
    // ...
}
Atal answered 8/6, 2018 at 22:25 Comment(0)
V
2

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.

Vaginitis answered 19/12, 2018 at 11:53 Comment(0)
E
1

Just change activity theme in manifest to any one like:

android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"
Elayne answered 24/1, 2018 at 9:17 Comment(0)
E
1

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

Escapade answered 31/3, 2018 at 19:42 Comment(2)
when I ansewered this question last build tools was 27.0.1 and it doesn't work for me, I think it was a fix done in 27.0.2 and that's good :)Tella
Yeah..its done on 27.0.2..your answer is also perfect. @TellaEscapade
L
0

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.

Lukewarm answered 19/1, 2018 at 16:40 Comment(0)
C
0

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.

Candlewick answered 23/4, 2018 at 14:17 Comment(0)
Z
0

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.

Zoller answered 26/9, 2018 at 15:21 Comment(0)
S
0

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'
Scrofulous answered 10/10, 2018 at 7:12 Comment(0)
R
0

upload gradle!

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

Relinquish answered 15/2, 2019 at 23:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.