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)

Tomasz Mularczyk
  • 34,501
  • 19
  • 112
  • 166
ik024
  • 3,566
  • 7
  • 38
  • 61

16 Answers16

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'
Nawrez
  • 3,314
  • 8
  • 28
  • 42
  • Thanks it solved for me. Does it mean buildToolVersion 26.0.2 has a bug ? – ik024 Nov 10 '17 at 16:25
  • I think so ! I tried with 26.0.2 but it doesn't work – Nawrez Nov 10 '17 at 16:52
  • 12
    Thanks! I used 27.0.2 instead, without any other changes in res/values/styles.xml and Manifest.xml, the problem just resolved. – BabyPanda Dec 05 '17 at 09:23
  • 4
    @BabyPanda : 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 :) – Nawrez Dec 05 '17 at 09:31
  • It Works for me – Avinash Jan 31 '18 at 09:43
  • @Nawrez 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? – Paradox Feb 01 '18 at 03:44
  • in my case I found that problem occur because I let my activity extends AppCompatActivity. Try to change AppCompatActivity to Activity and it works – ThaiPD Mar 16 '18 at 18:23
  • @ik024 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. – Sira Lam Mar 19 '18 at 08:21
  • OMG Android is so complicated! – Harsha Apr 14 '18 at 13:19
  • 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. – The Dark Brainer Nov 08 '18 at 02:54
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.

MobileEvangelist
  • 2,583
  • 1
  • 25
  • 36
Maysam R
  • 915
  • 10
  • 12
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.

Gent
  • 6,215
  • 1
  • 37
  • 40
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.

MobileEvangelist
  • 2,583
  • 1
  • 25
  • 36
mehmoodnisar125
  • 1,469
  • 18
  • 14
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

Pawar Shah
  • 81
  • 5
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

MohammadL
  • 2,398
  • 1
  • 19
  • 36
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.

DNB
  • 59
  • 5
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'
    // ...
}
Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
AhuraMazda
  • 460
  • 4
  • 22
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.

B.shruti
  • 1,589
  • 1
  • 21
  • 41
1

Just change activity theme in manifest to any one like:

android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"
Khalid Ali
  • 373
  • 1
  • 15
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

Mihir Joshi
  • 117
  • 4
  • 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 :) – Nawrez Apr 03 '18 at 09:54
  • 1
    Yeah..its done on 27.0.2..your answer is also perfect. @Nawrez – Mihir Joshi Apr 03 '18 at 10:22
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.

Jorgesys
  • 124,308
  • 23
  • 334
  • 268
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.

arekolek
  • 9,128
  • 3
  • 58
  • 79
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.

Harry .Naeem
  • 1,245
  • 3
  • 20
  • 33
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'
Jack
  • 1,825
  • 3
  • 26
  • 43
0

upload gradle!

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