• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Build.gradle dependency error

Cetnix

Lurker
Aug 16, 2018
8
1
Hello everyone, I'm building a utility app with ads. I'm currently having a problem at the build.gradle(app) choosing the correct compilesdk,buildtoolsversion and targetsdkversion. Can you help me out? Thanks.
 

Attachments

  • IMG_20190123_164506.jpg
    IMG_20190123_164506.jpg
    369 KB · Views: 118
  • IMG_20190123_164529.jpg
    IMG_20190123_164529.jpg
    294 KB · Views: 75
  • IMG_20190123_164538.jpg
    IMG_20190123_164538.jpg
    314.5 KB · Views: 114
Hello everyone, I'm building a utility app with ads. I'm currently having a problem at the build.gradle(app) choosing the correct compilesdk,buildtoolsversion and targetsdkversion. Can you help me out? Thanks.

Please try to post code instead of images as it's easier to sort through and help you.

I looked through a couple of the images and seems you need some adjustments and you'll be fine. I'll post what a newly created project should look like for you to reference.

The build.gradle file in the root of your project should be exactly as follows...
Code:
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
     
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
     
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
     
    }
}

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

Now as for the build.gradle file in your app directory you should targetSdkVersion 28 which is the latest. Your appcompat should be v7:28.0.0, also the latest. Here's the build.gradle from a working sample project for you to reference...
Code:
apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.YOUR.APP.HERE"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
}

New created projects in the latest version of Android Studio don't seem to use buildToolsVersion in the build.gradle, but if you need it, this is the latest...
Code:
buildToolsVersion '28.0.3'

If you set minifyEnabled and shrinkResources to true you may get some build errors if you use Adsense and/or ShareActionProvider. This can easily be fixed with some proguard rules. Have a look at the tutorial in this link for how to do it...
https://techstop.github.io/reduce-apk-size/

One thing you should be aware of is that the appcompat support library will according to google, not be updated past version 28 and will eventually be deprecated. Instead you should be making the switch to the AndroidX appcompat support library.

To use the AndroidX library just change your dependency to this...
Code:
implementation 'androidx.appcompat:appcompat:1.0.2'

Read about the AndroiX library and benefits here...
https://developer.android.com/jetpack/androidx/
 
Last edited:
Upvote 0
Please try to post code instead of images as it's easier to sort through and help you.

I looked through a couple of the images and seems you need some adjustments and you'll be fine. I'll post what a newly created project should look like for you to reference.

The build.gradle file in the root of your project should be exactly as follows...

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'><tt>// Top-level build file where you can add configuration options common to all sub-projects/modules. </tt></li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>  </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>buildscript { </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>    repositories { </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>        google() </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>        jcenter() </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>      </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>    } </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>    dependencies { </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>        classpath 'com.android.tools.build:gradle:3.3.0' </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>      </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>        // NOTE: Do not place your application dependencies here; they belong </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>        // in the individual module build.gradle files </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>    } </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>} </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>  </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>allprojects { </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>    repositories { </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>        google() </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>        jcenter() </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>      </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>    } </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>} </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>  </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>task clean(type: Delete) { </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>    delete rootProject.buildDir </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>} </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>[/LIST] Now as for the build.gradle file in your app directory you should targetSdkVersion 28 which is the latest. Your appcompat should be v7:28.0.0, also the latest. Here's the build.gradle from a working sample project for you to reference... </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'><tt>apply plugin: 'com.android.application' </tt></li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>  </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>android { </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>    compileSdkVersion 28 </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>    defaultConfig { </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>        applicationId 'com.YOUR.APP.HERE' </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>        minSdkVersion 15 </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>        targetSdkVersion 28 </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>        versionCode 1 </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>        versionName '1.0' </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>    } </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>    buildTypes { </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>        release { </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>            minifyEnabled true </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>            shrinkResources true </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>        } </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>    } </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>} </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>  </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>dependencies { </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>    implementation fileTree(dir: 'libs', include: ['*.jar']) </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>    implementation 'com.android.support:appcompat-v7:28.0.0' </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>} </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>[/LIST] New created projects in the latest version of Android Studio don't seem to use buildToolsVersion in the build.gradle, but if you need it, this is the latest... </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'><tt>buildToolsVersion '28.0.3' </tt></li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>[/LIST] If you set minifyEnabled and shrinkResources to true you may get some build errors if you use Adsense and/or ShareActionProvider. This can easily be fixed with some proguard rules. Have a look at the tutorial in this link for how to do it... </li>
<li dir='ltr'>https://intechgeek.com/reduce-apk-size/ </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>One thing you should be aware of is that the appcompat support library will according to google, not be updated past version 28 and will eventually be deprecated. Instead you should be making the switch to the AndroidX appcompat support library. </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>To use the AndroidX library just change your dependency to this... </li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'><tt>implementation 'androidx.appcompat:appcompat:1.0.2' </tt></li>
</ul>

<ul style='margin-top:0; margin-bottom:0;'>
<li dir='ltr'>[/LIST] Read about the AndroiX library and benefits here... </li>
<li dir='ltr'>https://developer.android.com/jetpack/androidx/
</li>
</ul>

Add this to your .bashrc file:

export LC_ALL=C

I suggest this because of certain changes made in Repo's newer than Nougat 7.1 (SDK #25) and distro's newer than Ubuntu 16.04 makes harder for gradle to find & build apps properly without some kind of path directory
 
Last edited:
  • Like
Reactions: GameTheory
Upvote 0
</li>
</ul>

Add this to your .bashrc file:

export LC_ALL=C

I suggest this because of certain changes made in Repo's newer than Nougat 7.1 (SDK #25) and distro's newer than Ubuntu 16.04 makes harder for gradle to find & build apps properly without some kind of path directory

Thanks for the tip. If I ever have a build issue of the sort, I'll know where to start.

Don't try to make his job harder with less ppl to be able to make use of his app SDK25 should be decent enough cuz lots of ppl still on Nougat

I have to disagree. Any seasoned app developer and google developers as well will tell you to target the latest SDK. You can set your min SDK to whatever you need, but target should be set to the latest. Forward compatibility in android is rock solid, so targeting the latest will not break your app or cause difficulty. This will also open your access to the latest APIs for use in your app.

https://developer.android.com/distribute/best-practices/develop/target-sdk

https://medium.com/androiddeveloper...n-minsdkversion-targetsdkversion-a098a0341ebd

The first sentence in the first link sums it up.
 
Last edited:
  • Like
Reactions: bcrichster
Upvote 0
Please try to post code instead of images as it's easier to sort through and help you.

I looked through a couple of the images and seems you need some adjustments and you'll be fine. I'll post what a newly created project should look like for you to reference.

The build.gradle file in the root of your project should be exactly as follows...
Code:
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
     
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
     
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
     
    }
}

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

Now as for the build.gradle file in your app directory you should targetSdkVersion 28 which is the latest. Your appcompat should be v7:28.0.0, also the latest. Here's the build.gradle from a working sample project for you to reference...
Code:
apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.YOUR.APP.HERE"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
}

New created projects in the latest version of Android Studio don't seem to use buildToolsVersion in the build.gradle, but if you need it, this is the latest...
Code:
buildToolsVersion '28.0.3'

If you set minifyEnabled and shrinkResources to true you may get some build errors if you use Adsense and/or ShareActionProvider. This can easily be fixed with some proguard rules. Have a look at the tutorial in this link for how to do it...
https://intechgeek.com/reduce-apk-size/

One thing you should be aware of is that the appcompat support library will according to google, not be updated past version 28 and will eventually be deprecated. Instead you should be making the switch to the AndroidX appcompat support library.

To use the AndroidX library just change your dependency to this...
Code:
implementation 'androidx.appcompat:appcompat:1.0.2'

Read about the AndroiX library and benefits here...
https://developer.android.com/jetpack/androidx/
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones