Android build fails for task: ':app:transformClassesWithDexForDebug' - android

I just started a project with my Android Studio. I suddenly started to have problems with layout preview. Preview renders the screen normally but I get an annoying Rendering Problems window that says:
Rendering Problems The following classes could not be found:
- android.support.v7.internal.app.WindowDecorActionBar (Fix Build Path, Create Class)
Tip: Try to build the project.
Of course, I tried many things.
build the project
clean and rebuild the project
clean, rebuild, sync and then rebuild again
cleaning app data before doing any of the above
uninstalled and reinstalled the android studio and then repeated the above steps.
Any idea what the problem might be?
My build.gradle is:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply plugin: 'com.android.application'
android {
signingConfigs {
}
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "gr.asd.asdapp"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
jumboMode = true
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}

As suggested here
Rendering Problems The following classes could not be found: android.support.v7.internal.app.WindowDecorActionBar
Change your theme to inherit from a Base Theme.
<style name="AppTheme" parent="Theme.AppCompat.Mpla.Mpla">
<!-- Customize your theme here. -->
</style>
with
<style name="AppTheme" parent="Base.Theme.AppCompat.Mpla.Mpla">
<!-- Customize your theme here. -->
</style>
Android Studio has a terrible out-of-the-box experience. But it used to be worse. A completely new project that was not using the latest API would yield Obsolete class errors and you had to replace Activity with AppCompatActivity to make it work
Having said that, if you target the latest API your problem will be gone but obviously that's not a solution :)

Related

Android Studio Gradle Build failing - asking for a sdk version that doesn't exist

24 hours ago my project built perfectly, no errors. Without changing a single piece of code, it will no longer build when I have resumed work.
Checking out to older working commits now produces the same error.
These are the error codes I get:
Information:Gradle tasks [assemble]
Error:(9, 5) error: resource android:attr/dialogCornerRadius not found.
/home/liam/.gradle/caches/transforms-1/files-1.1/appcompat-v7-28.0.0-alpha1.aar/536e4dd78846259cf8bef0fd6a3ea0e6/res/values/values.xml
I think that this has been caused by Android P being released and my Android Studio automatically upgrading or something like that. Which would explain why old commits that worked get this same error.
This would be a very new issue, which would explain why I cannot find a solution to it yet.
Searching these error codes leads to a similar issue that was resolved by changing the SDK version in the gradle build file. My problem differs from this because changing to SDK 28 (I'm pretty sure 28 doesn't even exist) leads to android studio saying this package isn't available/doesn't exist for download.
How to find issue Android SDK 3.0 Error:(9, 5) error: resource android:attr/colorError not found
Clicking on the first mentioned error codes leads to a file called v28/values-v28.xml being opened.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Base.Theme.AppCompat" parent="Base.V28.Theme.AppCompat"/>
<style name="Base.Theme.AppCompat.Light" parent="Base.V28.Theme.AppCompat.Light"/>
<style name="Base.V28.Theme.AppCompat" parent="Base.V26.Theme.AppCompat">
<!-- We can use the platform styles on API 28+ -->
<item name="dialogCornerRadius">?android:attr/dialogCornerRadius</item>
</style>
<style name="Base.V28.Theme.AppCompat.Light" parent="Base.V26.Theme.AppCompat.Light">
<!-- We can use the platform styles on API 28+ -->
<item name="dialogCornerRadius">?android:attr/dialogCornerRadius</item>
</style>
</resources>
Here are my gradle files:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.timelord.timelord.timelord"
minSdkVersion 24
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'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:+'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation files('libs/joda-time-2.9.9.jar')
}
And
// 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.0.1'
// 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
}
You have the design lib version with + in your build.gradle which means it will download the latest version. So please set it to 26.1.0 and it should work. The support 28 is in alpha and was released yesterday with the new android P preview
Make sure in your app's build.gradle you have these:
dependencies {
compile 'com.android.support:support-v13:27.+'
compile 'com.android.support:design:27.+'
}

Getting Rendering issue in Android Studio, Views are not Displaying

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.

Toolbar: IllegalStateException - configure your build for VectorDrawableCompat

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.

Framework code "can't resolve symbols" in Android Studio

I am trying to debug through library code in Android Studio. But it shows unresolved symbols, i.e., red lines at lots of places.
My app build.gradle looks like:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.kuldeep.customview"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
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.1.1'
}
My project build.gradle file is:
// 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:2.0.0-beta2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
You're looking at the code for TextView, which is an Android platform class and not part of your app. Platform classes can refer to other "package private" classes that are not part of the visible API for an app. Android studio provides for you the ability to view platform source code like this so you can see how it works, but you can't make changes to it and you don't get access to all the actual compiled classes in the SDK.
The short story is that is regular and expected. If you were seeing this for your own app code (not platform classes or add-on libraries) then you'd have something to be concerned about.
2 possible reasons:
Gradle not synced.
Try syncing your gradle files using Gradle Sync.
SDK not updated.
Make sure your SDK is updated and that you have all the extra packages that you need installed. You can do that using SDK Manager.

App runs correctly once, subsequent runs open blank white screen

I updated to Android Studio 1.0 today from 0.8.14. Most of the update was seamless, the IDE fixed a few things itself. I was using an older version of the gradle build tools, 0.12 and had to change this to 1.0.0. I also upped the buildToolsVersion defined in my inner build.gradle to 21.1.1
One project I'm working on is exhibiting very strange behaviour since I updated. I can push it to a device and it will install and open, but after I kill the app any subsequent attempts to open it don't work. A plain white screen is displayed instead. The app doesn't hit my launch activity, it doesn't instantiate the application. I can't get any information through debugging, nothing is reported from the device. This happens with both debug and release builds, and across the three flavours I've defined. I've tested on multiple phones running Lollipop and Kitkat and on Genymotion VMs.
I've included my build.gradle files below as I feel this must be something to do with the build steps taken to make the apk, but I don't know where to begin fixing this. Any help would be greatly appreciated.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
mavenCentral()
}
}
inner build.gradle
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:21.0.2'
compile "com.android.support:appcompat-v7:21.0.2"
compile 'com.google.android.gms:play-services:6.5.87'
compile 'io.keen:keen-client-api-android:2.0.1#aar'
compile 'com.google.code.gson:gson:2.3'
compile(name: 'my-lovely-aar', ext: 'aar')
}
repositories {
flatDir {
dirs 'libs'
}
mavenCentral()
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
productFlavors {
beta {
applicationId 'com.project.beta'
}
prod {
applicationId 'com.project.prod'
}
dev {
applicationId 'com.project.dev'
}
}
defaultConfig {
minSdkVersion 15
targetSdkVersion 21
versionCode 8
versionName "1.1.1"
}
signingConfigs {
release {
// details for release builds
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
lintOptions {
abortOnError false
}
}
I found my problem.
compile 'com.google.android.gms:play-services:6.5.87' is the guy that broke it. I still don't know the why, but having that dependency stops my app from opening. Including earlier version of the play services lib, like 6.1.11, works perfectly. I don't have 6.1.88/83/74 to test with but I suspect they'd all be fine too.

Categories

Resources