Android Studio -- Designer screen blank - android

I created a new Android Project in Android Studio 3.1.3 on Windows 7:
included Kotlin support
API 15: Android 4.0.3
Basic Activity
I opened content_main.xml in Design View. Even though it will have a TextView saying "Hello World" by default, this was not shown on the Design screen. Instead, what I am shown is a blank screen with "android...CoordinatorLayout" text in the center:
My build.gradle (Module: app) file is:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.test.myapplication"
minSdkVersion 15
targetSdkVersion 28
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"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:28.0.0-alpha3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Simply put, there is a problem with the versions of com.android.support:appcompat-v7 and com.android.support:design referenced, which cause the Designer to fail. Therefore you need to downgrade from API 28 down to 27 in order to use dependencies of version 27.1.1 for these dependencies. In build.gradle (Module: app):
Change compileSdkVersion to 27
Change targetSdkVersion to 27
Reference 27.1.1 for com.android.support:appcompat-v7
Reference 27.1.1 for com.android.support:design
This is how the file will look after you make the changes:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.test.myapplication"
minSdkVersion 15
targetSdkVersion 27
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"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Once you make the changes to build.gradle, a pop-up will ask you to "Sync Now", if you click on it, then after syncing, your designer will work:
(If you don't have version 27 of the SDK platform installed, then go to Tools → SDK Manager, and install Android 8.1 (Oreo) -- its API level is 27.

Related

Downgrade Android SDK from 29 to 21

I need to downgrade my SDK to 21 in order to test some deprecated features that are no longer working properly on SDK 29. But when I lower SDK and sync project it gives an error when compiling app.
The error is C:\Users\user\.gradle\caches\transforms-2\files-2.1\93bc303e0edf41378a70a682ebb74605\appcompat-1.1.0\res\values-v26\values-v26.xml:5:5-8:13: AAPT: error: resource android:attr/colorError not found.
Here are my build.gradle settings
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 21
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.example.oldstuff"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
What should be added/removed?
This issue occurs when you use compileSdkVersion and buildToolsVersion less than 26
Your compileSdkVersion is 21, but it can be possible that third party libraries use resources that were only added in API 26 or later. Either update your build.gradle file to use the newest compileSdkVersion or try to downgrade third party libraries.

how to solve the problem of "Inconsistencies in the existing project dependencies found"?

I am learning to write android apps by watching some tutorials on youtube. I follow the tutorials and try to add the recyclerview in the xml file. When I click the download button next to the recyclerview, the following message is shown:
"This operation requires the library androidx.recyclerview:recyclerview:+.
Problem: Inconsistencies in the existing project dependencies found.
Version incompatibility between:
- androidx.appcompat:appcompat:1.1.0#aar
and:
- androidx.core:core-ktx:1.1.0#aar
With the dependency:
- androidx.annotation::1.1.0
versus:
- androidx.annotation::2.0.0
The project may not compile after adding this library.
Would you like to add it anyway?"
If I choose OK and go ahead, the preview screen becomes grey.
What should I do to solve the problem?
The same problem occurs when I want to add the cardview in the xml file.
thanks in advance!!!!
The build.gradle is below:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.smartherd.msgshareapp"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Just build the project again and manually refresh the layout. :)

Why a new project templates in Android Studio 3.2.1 does not use the AndroidX libraries?

Google says
"We recommend using the AndroidX libraries in all new projects. You
should also consider migrating existing projects to AndroidX as well."
source
but the Android Studio 3.2.1 still creates a new project templates which are supported by the historical "android.support.*" libraries.
Why?
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.developer.myapplication"
minSdkVersion 15
targetSdkVersion 28
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"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-vector-drawable:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Not until Android Studio 3.3 or higher (currently still Preview/Beta).
If you create a new project with it, you'll find this Use AndroidX artifacts option. Then once created, you'll find that the dependencies are defaulted with androidx.*

Android Studio design view not displaying correctly

I have looked at numerous sites and the suggestions provided here at Stack Overflow. Everything works fine with my Android Studio, except the design view does not display anything. I can drag and drop widgets or modify the XML code by hand and the text gets updated fine, but the changes just don't register on the design or blueprint. I have tried deleting and reinstalling the IDE, changing the SDK version, doing build--> clean, resetting the cache, and adding dependencies. Below is my build.gradle Anyone with a critical eye have suggestions? I don't know what I'm doing.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.mydrinkmixer.somerestaurant.mydrinkmixer"
minSdkVersion 15
targetSdkVersion 28
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"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

How to display Map on emulator

From Android Studio, I created a Map Activity project; so, there's no custom code.
The only custom changes made was copying the URL from the google_maps_api.xml _(https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=)_ and using it to create an API key.
Android Studio: 3.0.1
Emulator: Nexus 5X with API 25
Build.gradle file
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 26
defaultConfig {
applicationId "xxxx.xxx.xxxx"
minSdkVersion 19
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"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.google.android.gms:play-services-maps:11.0.0'
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'
}
Screenshot
It seems like I'm missing something; I just don't know what it is.
Try to run in your mobile. Sometimes emulator is not able to load map properly, That's why it shows blank map without loading roots.

Categories

Resources