I'm using Android Studio 2.1.2. I started a new project with minSdkVersion as 19. My activity extends AppCompatActivity. The project starts with an empty activity using a fragment.
When previewing content_main.xml with API 24, all is good. when previewing API 19, I get the following rendering problem:
The following classes could not be instantiated:
- android.support.v7.widget.Toolbar
java.lang.IllegalStateException: This app has been built with an incorrect configuration. Please configure your build for VectorDrawableCompat
I have added every thing I found relevant to the gradle (2 files):
classpath 'com.android.tools.build:gradle:2.1.2'
vectorDrawables.useSupportLibrary = true
buildToolsVersion "24.0.1"
compile 'com.android.support:appcompat-v7:24.1.1'
compile "com.android.support:support-v4:24.1.1"
compile 'com.android.support:design:24.1.1
But still the error appears. I've found a lot of answers on internet. But none helped. Is there a problem using the new toolbar with API 19?
This worked well for me
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.app"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
generatedDensities = []
}
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
additionalParameters "--no-version-vectors"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Notice this in the above code:
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
additionalParameters "--no-version-vectors"
}
and
generatedDensities = []
from this google Issue
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
check this issue for more help.
UPDATE
configured your app build.gradle file as follows
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
}
Source
Age Of Vectors
Firstly, there are two types of gradle files.
build.gradle(Project: ProjectName)
build.gradle(Module: app)
For more information on these two files, go through this answer.
Coming to your question,
I've found a lot of answers on the net but none helped. I'm using
Android Studio 2.1.2, my activity extends AppCompatActivity and added
to the gradle (2 files) every thing I found relevant: but still the
error appears.
From whatever you have posted, it seems like you didn't add right things at right places.
You shouldn't place your application dependencies in build.gradle(Project: ProjectName) - Android Studio says,
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Hence, replace your dependencies in build.gradle(Project: ProjectName) with below
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
Replace your dependencies in build.gradle(Module: app) with below
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
}
After doing as mentioned above, you will see a "Sync Now" option on the Top Right. Click it. Android Studio will take care of remaining things.
Also this question similar is to yours. Go through it. It may help.
Add :
build.gradle
defaultConfig {
...
vectorDrawables.useSupportLibrary = true
...
}
And on top of your Activity class:
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
And one last thing put your vector drawables inside any other drawables like selector, LayerList, etc. Something like below:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/drawable_vector" />
</selector>
And use this above drawable everywhere instead of setting vector drawables directly. This will at other places as well whenever you want to use vector drawables on pre-lollipop devices.
Related
I'm trying to get into developing using android studio, so I recently tried to run a simple login-activity app on it. Basically, what I did was just run the setup for a new android studio project, and selected loginactivity as my default screen. I configured the emulator and hit sync gradle, but it gave me the following response:
image
I downloaded the repository that was required and tried to sync the gradle again, but it again asked exactly the same thing! Please help!
my gradle file for the app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.fyp.fingerpay"
minSdkVersion 23
targetSdkVersion 27
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.google.android.gms:play-services:10.2.6'
compile 'com.android.support:appcompat-v7:27.+'
}
I think you have forgot to add maven repository in your app gradle file.
Try by doing these steps.
Open the build.gradle file for your application.
Make sure that the repositories section includes a maven section with the "https://maven.google.com" endpoint. For example:
allprojects {repositories {jcenter()maven {url "https://maven.google.com"}}}
Avoid using + in your dependencies as it android studio will try to update dependencies every 24 hours.
Also replace compile by implementation for low APK size.
This is my gradle , I search over internet many times but i am not getting any solution . I already used many thing to solve but i am not getting eject answer to my question, Please help me.
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.0'
dataBinding { enabled = true }
defaultConfig {
applicationId "com.android.application"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] } }
}
dependencies {
testCompile 'junit:junit:4.12'
compile 'cz.msebera.android:httpclient:4.4.1.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.+'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile(name: "truesdk-0.5", ext: "aar")
}
apply plugin: 'com.google.gms.google-services'
I faced the same problem. Actually this problem comes from style.xml
Each new version of Android provides a new API level and new features.
If you are following someones code and they are using something like extends ActionBarActivity or just extends Activity, that was fine for the SDK API the were using at the time they wrote it.
When you start a new blank activity (or in version24 an empty activity), AND the min API you want to support is less than the current API, Android will create the activity extending AppCompatActivity. Id does this so it can support older API levels.
The theme is tied to the Activity type the Activity extends.
Solutions are :
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
or,
First you have to Sync your project.
Next, go to Build menu, and clic on the Clean Project.
Finally, again, go to Build menu, and clic on the Rebuild option.
Verdant newbie here. I'm making a fairly simple project that needs to be compatible with Android versions older than Lollipop, but still want to have the app look nicer by using AppCompat.
Unfortunately, I do not know how to work (or even find) the gradle - I tried to run a gradle task: compile "com.android.support:appcompat-v7:21.0.+"
But it returned an error saying that "Task 'compile' is ambiguous...." in my project.
Could anyone tell me how to add this? I've searched all over Google, but everything goes way over my head.
Thanks!
Have you been able to locate Gradle file?
Edit your gradle like this :
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.xyz.xyz"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.00.00"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
}
Update your question and post full Gradle code.
Add the appcomapt library(com.android.support:appcompat-v7:21.0.+") in dependancy section of the build.gradle file
Or second way to add library is by searching on maven repo.this can be done by traversing file->project structure->app>dependancy->click (+) ->add Library dependancy
Task 'compile' is ambiguous.
This issue is not the Compile Issue. but this was an issue on the task itself.
if you are not using a command like "gradle compileDebug" then one of the android configurations are executing the task and it is not working well with your build.gradle.
Here is a link that seems to relate specifically to your issue. Click Here
I'm trying to implement data-binding in android app. This is the link I'm following to set it up. Even after doing all the necessary implements, I'm getting the following error in gradle-build:
error: package com.example.satpracticeapp.databinding does not exist.
(This package is what I'm importing in my MainActivity.java file)
I tried this (the data-binding compiler), but it didn't work.
The problem is I've already successfully tried a hello-world app using data-binding and it works. But, when I try to implement it in an app I made a few weeks ago, I get the error I mentioned above. Searching for the solutions, I copy-pasted the gradle files from my successful hello world app to my old app - that too didn't work out.
Here is my app level build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.satpracticeapp"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.0'
}
And here's the buildscript of the project level build.gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
Here are the links to the minimal version of the three files (if it's needed)
MainActivity.java
ViewModel.java
activity_main.xml
After much hair-pulling, I couldn't figure out the solution and getting the same build error again and again.
So, as a temporary solution, I'm trying to copy-paste my classes and layouts in the working hello world project. What am I missing?
EDIT:
After a few hours of pointless searching, I went back to my code. Checked it word by word and found a typing mistake at the name of a binding variable in the xml file.
Everything works fine now!
I had the same issue, turned out to be a duplicate symbol declaration in one of my *.java classes. It's shown in the Gradle console but it was kinda hidden among the databinding errors. i had about 72 data binding errors and this duplicate symbol error was in the middle so it's easy to miss.
I'm in the process of converting an existing app from Eclipse to Android Studio. However, when I run it on a device running 4.x (I've tested several versions on emulators), it immediately crashes with a NoClassDefFoundError.
I've tried commenting out references to the classes it can't find, but there's always another. As far as can tell, the offending class is always
Within my own code
An inner class (Update: With more investigation, this one isn't always true)
Everything works fine on a 5.0.1 emulator (I don't have a device to test on). My build.gradle file is fairly long, but looks like this:
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = "2.7.1"
android {
compileSdkVersion 19
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.myapp.android"
minSdkVersion 8
targetSdkVersion 19
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
*snip*
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
repositories {
maven {
url "https://repo.commonsware.com.s3.amazonaws.com"
}
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName 'com.pact.android'
}
}
dependencies {
*snip compile project(':...') declarations
apt "com.googlecode.androidannotations:androidannotations:$AAVersion"
compile "com.googlecode.androidannotations:androidannotations-api:$AAVersion"
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.google.android.gms:play-services:3.1.36'
*snip many more compile declarations*
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Some examples of classes that cause trouble:
An anonymous class that implements an interface inside the facebook library (as a library project)
Parcelable.CREATOR implementations in my models
An inner class that extends android.os.Library
An inner class in my own code
A class that implements an interface in a library from maven
What's going wrong, and how do I fix it?
I was incompletely implementing MultiDex support, so some of my classes weren't in the proper dex file. To fix it, you have to do more than just set multiDexEnabled = true in your defaultConfig block. You also have to:
Include compile 'com.android.support:multidex:1.0.1' in your dependencies
Have your Application class extend MultiDexApplication instead of just Application. Alternatively, you can call MultiDex.install() in attachBaseContext() of your application.
See https://developer.android.com/tools/building/multidex.html for more details.
1) Add multiDexEnabled = true in your default Config
2) Add compile com.android.support:multidex:1.0.0 in your dependencies
3) Application class extend MultiDexApplication instead of just Application
1) add multiDexEnabled = true in your defaultConfig in build.gradle.
2) You also have to Include compile 'com.android.support:multidex:1.0.1'
3) add the following to your "application" tag in your manifest:
android:name="android.support.multidex.MultiDexApplication"
its working with me , hope that help
I solved the problem by removing multiDexEnabled = true in my case.
I also issue get resolved after doing following steps
1) add multiDexEnabled = true in your defaultConfig in build.gradle.
2) You also have to Include compile com.android.support:multidex:1.0.1
3) add the following to your "application" tag in your manifest:
android:name="android.support.multidex.MultiDexApplication"
I got the same issue, tried all solutions suggested on StackOverflow but they did not work in my case.
After that I found out that one of libraries compiled by Java 8. So, I need to enable Java 8 in my project too.
android {
//...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
There are many reasons which leads to this error. Hope it helps.
In my case, it was Kotlin forEach was causing the exception.
More info here: java.lang.NoClassDefFoundError $$inlined$forEach$lambda$1 in Kotlin