I have two projects: library and app. I have previously uploaded library to jCentre, and library is listed as an external dependency of app in its build.gradle file. Recently I published a newer version of library and updated the dependency version code in app's build.gradle file, but when I did this Android Studio could no longer find any of the classes from library.
To test the library, I created an entirely new project and added library as a dependency. In this scenario Android Studio finds the classes just fine. I've compared every line of the build.gradle files: They have the same min and target SDK version, they have the same proguard config, they're literally identical. They projects are also using the exact same version of the android plugin and the exact same gradle version.
I also tried entirely deleting app from my machine and re-checked it out from git. This did not solve the problem. I've tried all the usual steps of cleaning the project and rebuilding the project, deleting all build files, invalidating caches, etc.
So can anyone tell me why Android Studio cannot find any of the library classes after upgrading the dependency version?
Here is the gradle.build file in the new test project:
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
minSdkVersion 11
targetSdkVersion 24
versionCode 11
versionName "3.1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.matthew-tamlin:android-utilities:2.1.0' // this is library
}
Here's the build.gradle file in the app project:
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
minSdkVersion 11
targetSdkVersion 24
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.matthew-tamlin:android-utilities:2.1.0' // this is library
}
You can see that they're virtually identical, so why can one project find the classes from the library but the other cannot?
So I never discovered why this is an issue, but I found a workaround. I created a new project in Android Studio and copied all the src directories and build.gradle files from the existing project. I also copied the hidden git folder and all git ignore files. I didn't copy the gradle wrapper, the gradle file or the generated builds. I don't know why this fixed the problem, it must be a bug in gradle or Android Studio.
Related
I am trying to sync my project with the Gradle files but every time I do it I get the same error message:
WARNING: The specified Android SDK Build Tools version (27.0.0) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.2.1.
My target SDK version is API 24 since I am developing an app for an Android 7.0 (Nougat) operating system.
I looked over the Android Developers site: https://developer.android.com/ and I can't find anything about what Android Gradle Plugin corresponds with which target SDK version. I've read several Stack Overflow questions where people asked about which specific Android Gradle Plugin they need for their project but none of the questions were about where to go to find that information.
Can anyone tell me how to know which Android Gradle plugin version I need?
Here are the two build.gradle files in my app folder:
(Module: app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion '27.0.0'
defaultConfig {
applicationId "com.android.example.favoritetoys"
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
debuggable true
}
debug {
applicationIdSuffix ".debug"
debuggable true
}
}
}
(Project)
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:3.2.1'
}
}
allprojects {
String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains("windows")) {
buildDir = "C:/tmp/${rootProject.name}/${project.name}"
}
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Since AGP (Android Gradle Plugin) version 3.0.0, there is a minimum version requirement for the Android Build Tools version, which is a designed behaviour.
See
http://google.github.io/android-gradle-dsl/current/com.android.build.gradle.AppExtension.html#com.android.build.gradle.AppExtension:buildToolsVersion
So, if you want to force your project to use an older version of build tools, i am afraid that you need to downgrade your AGP to a version below 3.0.0.
But, question for you is why do have to use the older build tools?
As seen from https://developer.android.com/studio/releases/build-tools.
You should always keep your Build Tools component updated by
downloading the latest version using the Android SDK Manager.
For your cross reference about the differences among the three different version configurations in build.gradle, i.e. compileSdkVersion, targetSdkVersion and minSdkVersion.
What is the difference between compileSdkVersion and targetSdkVersion?
What is the difference between min SDK version/target SDK version vs. compile SDK version?
For your case, maybe you only need to change your targetSdkVersion to 28.
I try to move android TV app to Android studio. When I try to compile it, I had some import errors. I couldn't find the dependency that I can add to build.gradle to fix these problem. The list of the imports are:
import android.media.tv.TvContentRatingSystemInfo;
import android.media.tv.TvContract.WatchedPrograms;
import com.android.tv.tuner.data.nano.Track.AtscCaptionTrack;
import com.android.tv.tuner.data.nano.Track.AtscAudioTrack;
import com.android.tv.tuner.data.nano.Channel;
The build.gradle is :
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.android.tv"
minSdkVersion 23
targetSdkVersion 23
versionCode 1
versionName "1.0"
ndk {
moduleName "libtunertvinput_jni"
}
}
sourceSets {
main {
res.srcDirs = ['src/main/res', 'src/main/usbtuner-res']
jni.srcDirs = []
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/exoplayer.jar')
compile project(':common')
compile 'com.android.support:palette-v7:+'
compile 'com.android.support:support-v4:+'
compile 'com.android.support:support-annotations:+'
}
You can't import these because they have #SystemApi annotation. You can check this for the source code of TvContentRatingSystemInfo. I have also checked WatchedPrograms and it also has #SystemApi annotation. I have not checked the other three.
You need to be system app to access these. As you can see here, you need to push your app in the the \system\ folder. You can find detailed information about AOSP build system here.
Solution :
Changing your android.jar to the .jar in this github should enable you to access system API. The reason is your standard android.jar doesn't have system API. So you need to get framework.jar (by adb pull) from emulator and combine it with core.jar then you can have new android.jar which contains system API (system methods and classes are available in the framework.jar from emulator).
Moreover, you should push your apk to \system\priv-app\ folder to access some system API but I don't know why I can access system API without pushing my apk to \system\priv-app\ when I use .jar from that github account.
I feel like I don't write quite clearly but at least now you have more understandings of what you're facing.
android.media.tv and com.android.tv are part of Android SDK. So you don't need to include any additional libraries in gradle.build file.
Just make sure to:
Update your SDK tools to version 24.0.0 or higher
and
Update your SDK with Android 5.0 (API 21) or higher
Example,
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.tvapp"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
}
use this in your dependencies "com.android.support:support-media-compat:26.0.2"
and also use tool version "26.0.1"
compiled SDK version 26.
You can add dependencies in app level gradle.
compile 'com.google.android.libraries.tv:companionlibrary:0.1'
I am trying to import a project in Android Studio. This code supposedly works but I cannot seem to be able to build the project. This is the error that is produced when I am trying to build:
Error:Execution failed for task
':openCVLibrary2410:compileReleaseJava'.
Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to
point to the according directory.
I have searched for a solution, but what I found was was either referring to eclipse or changing the jdk position for
File > other Settings > Default Project Structure
Which is not a valid solution for me because I checked my previous Android Studio Projects and all have the same position
This is the stacktrace:
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':openCVLibrary2410:compileReleaseJava'.
mainProject Gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
FaceRecognition Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "eu.upcom.recred.facerec"
minSdkVersion 9
targetSdkVersion 9
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile files('libs/javacpp.jar')
compile files('libs/javacv.jar')
compile project(':openCVLibrary2410')
}
openCV2410 gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 8
targetSdkVersion 8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
While I was posting here the gradle files my eye caught something. I changed the build tools version from 'com.android.tools.build:gradle:1.1.0' to 'com.android.tools.build:gradle:2.2.2'and now it is building as it should
I had same problem, Here is problem on Java path. You can check you have set path of your java or JDK in system variable or not click Environment variable
Also check your Java JDK version.
Also this link have all details of How to set path.
I suggest to you can use this solution. It will be help to resolve your problem..
I know this question is asked many times, and i used all the Answers to to resolve my error. Here is my problem.
I tried almost all Answer present on So, so please before mark my question as Duplicate, please read my question care, i mentioned all steps that are answered on SO Questions.
Whenever i tried to run / build / clean project i got error * What went wrong:
Task 'stacktrace' not found in root project 'project'.
Library and Sdk i m using
ViewPagerIndicator - JakeWharton
Facebook SDK
PDK (Pinterest sdk)
gcm.jar
httpcore-4.4.4.jar
What i have tried so far
changed Gradle version from 2.2.1-all.zip to lower version
changes Gradle Build version
delete all Library and run
All library project minSdkVersion same (my project using minSdkVersion: 11 )
clean project and Rebuild
Invalidate cache and restart Android Studio
delete .idea and .gradle folder then Import project
Created new project and copy paste old Project into project but it also gives same error on build
deleted .gradle folder from user folder(i m using windows 7 )
try to build project using command line
Changed JDK version new jdk1.8.0_73 ( my project was build on jdk1.7.0_55 ) here is thread that said using new JDK version will resolve problem
here are Answers i follwed first solution , Second solution, third solution Fourth Answer and many more.
Temporary solution(it was working before but not now )
i have backup of project two week ago, i import that backup project and replace the files and it works
But when i do clean project error came again
here is app level build.gradle file
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "XXX"
minSdkVersion 11
targetSdkVersion 23
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile project(':library')
compile files('libs/picasso-2.5.2.jar')
compile files('libs/jsoup-1.8.3.jar')
compile files('libs/httpcore-4.4.4.jar')
compile 'com.google.android.gms:play-services:8.3.0'
compile files('libs/gcm.jar')
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
}
android {
useLibrary 'org.apache.http.legacy'
}
Here is proejct level builld.gradle file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.google.gms:google-services:1.5.0-beta2'
}
}
allprojects {
repositories {
jcenter()
}
}
Help will be Appreciated!. Please share your ideas to resolve this error
i m trying to deal with error from 1 week and i m not getting answer from anywhere that will work for me
thanks
I have integrated Twitter and all is done well.
But now I need to create a reusable component.
I.e.: a library using the fabric sdk in android studio.
We can get the fabric plugin from the Twitter developer site.
By using that I'm able to add sdk to an Android Studio project, but not to a library.
How to add this sdk to an Android Studio library project?
Define the classpath in your project's build.gradle as usual.
Add the dependencies to your library module as you would suspect.
Apply the io.fabric plugin in your app module. No way around this, that's by design. Fabric needs application ID, libraries don't have one.
EDIT: Due to manifest merging you are able to specify the API key meta-data (e.g. for Crashlytics) in your library's manifest.
EDIT 2: Looks like there's a page for it. http://support.crashlytics.com/knowledgebase/articles/456258-library-subproject-in-gradle
https://docs.fabric.io/android/crashlytics/build-tools.html#set-up-a-library-subproject
For creating reusable component with fabric sdk.update your gradle to something like this
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.library'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile('com.twitter.sdk.android:twitter:1.3.2#aar') {
transitive = true;
}
}
Do rebuild your project after updating gradle file.you wil get the skd access now.