Rendering Problems: Android Studio - android-studio

I have just downloaded Android Studio, and when I try and create an Android Wear project it says:
Exception raised during rendering: android.support.wearable.view.WatchViewStub.requestApplyInsets()".
I've got no idea what this means or how I go about fixing it. My only guess was maybe SDK? This is what I've got:
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.helloworld.myapplication"
minSdkVersion 20
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:+'
compile 'com.google.android.gms:play-services-wearable:+'
}
And this is the error:
If anyone has any ideas I'd be most grateful!
Thanks
EDIT:
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.WatchViewStub
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/watch_view_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:rectLayout="#layout/rect_activity_my"
app:roundLayout="#layout/round_activity_my"
tools:context=".MyActivity"
tools:deviceIds="wear">
</android.support.wearable.view.WatchViewStub>

Related

java.lang.IllegalArgumentException: java.lang.ClassCastException after migrating to androidx in Android Studio

I recently migrated my example project to androidx. But, after migration, it causes 'Render Problem' in the preview. The project runs, nevertheless, but it would be helpful to get the preview working again.
As stated in the title, the render problem is caused by "java.lang.IllegalArgumentException: java.lang.ClassCastException
at java.lang.reflect.Method.invoke". A snippet is provided below.
java.lang.IllegalArgumentException: java.lang.ClassCastException#1a8e42ac
at sun.reflect.GeneratedMethodAccessor990.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at android.animation.PropertyValuesHolder_Delegate.callMethod(PropertyValuesHolder_Delegate.java:108)
at android.animation.PropertyValuesHolder_Delegate.nCallFloatMethod(PropertyValuesHolder_Delegate.java:143)
at android.animation.PropertyValuesHolder.nCallFloatMethod(PropertyValuesHolder.java)
at android.animation.PropertyValuesHolder.access$400(PropertyValuesHolder.java:38)
at android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:1387)
at android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:990)
at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:674)
at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:637)
at android.animation.ValueAnimator.start(ValueAnimator.java:1069)
at android.animation.ValueAnimator.start(ValueAnimator.java:1088)
at android.animation.ObjectAnimator.start(ObjectAnimator.java:852)
at android.animation.StateListAnimator.start(StateListAnimator.java:188)
at android.animation.StateListAnimator.setState(StateListAnimator.java:181)
at android.view.View.drawableStateChanged(View.java:21105)
at android.view.ViewGroup.drawableStateChanged(ViewGroup.java:7101)
at com.google.android.material.appbar.AppBarLayout.drawableStateChanged(AppBarLayout.java:393)
at android.view.View.refreshDrawableState(View.java:21160)
at android.view.View.dispatchAttachedToWindow(View.java:18379)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3397)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:42)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:335)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:391)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:195)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:540)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$5(RenderTask.java:666)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
This is my layout file:
<?xml version="1.0" encoding="utf-8"?>
<merge>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="56dp"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
<com.google.android.material.tabs.TabLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/tabs">
</com.google.android.material.tabs.TabLayout>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</merge>
This is my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.materialdemo"
minSdkVersion 21
targetSdkVersion 28
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 'androidx.appcompat:appcompat:1.1.0-alpha05'
implementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta1'
androidTestImplementation 'androidx.test:runner:1.2.0-beta01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-beta01'
implementation 'com.google.android.material:material:1.1.0-alpha06'
implementation 'androidx.constraintlayout:constraintlayout-solver:1.1.3'
implementation 'com.instabug.library:instabug:8.0.15.6-SNAPSHOT'
}
My project level build.gradle file:
// 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.4.1'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they
belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven{
url "https://oss.sonatype.org/content/repositories/snapshots"
}
maven {
url "https://jitpack.io"
}
maven {
url "https://dl.bintray.com/drummer-aidan/maven/"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Going back to implementation 'com.google.android.material:material:1.0.0' and invalidating the caches via File -> Invalidate Caches / Restart... works for me.
Also, any other theme like Theme.AppCompat.Light.NoActionBar works great, too.
Edit: I did not know that nearly no feature available in com.google.android.material:material:1.1.0-alpha06 is available in 1.0.0. So this answer is more or less useless.

Icons look flat in action bar

I've recently "upgraded" my android project to SDK version 26, and now the icons in my app bar look like this (run on Android 6.0), although the icon itself looks like this. I've got no idea why this is happening, I didn't change anything in the java or xml code that seems to be related to this.
I would be very happy if someone posted a solution to this as this could be a bigger problem once Android 8 is released.
build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.1'
defaultConfig {
applicationId "de.jamesbeans.quadrasolve"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "digit1.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:26.0.1'
compile 'com.android.support:percent:26.0.1'
}
relevant part of activity_main.xml:
<android.support.v7.widget.Toolbar
android:id="#+id/maintoolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimaryDark"
android:theme="#style/Widget.AppCompat.ActionBar"
android:visibility="visible"
app:popupTheme="#style/Theme.AppCompat.Light"
app:title="QuadraSolve"
app:titleTextColor="#android:color/background_light" />
relevant part of MainActivity.java:
Toolbar maintoolbar = (Toolbar) findViewById(R.id.maintoolbar);
setSupportActionBar(maintoolbar);
...
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.mainmenu, menu);
return true;
}
mainmenu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_history"
android:icon="#mipmap/ic_history_48px"
android:title="#string/history"
app:showAsAction="ifRoom">
</item>
</menu>
Had the same issue and stumbled across this answer which seems to have fixed the problem:
https://stackoverflow.com/a/45344964/4579919
The matter is that the icon size is bigger then the expected. Obviously the scaling mechanism has changed in SDK 26 and now it leads to this UI bug. Make sure the toolbar icon resources are provided in the following sizes.

How can I solve Android studio API platform

When I create a new project in Android studio I chose 2.3 for API level but when the project installed in platform 4.0.0 it stopped! It works just in 5.0.0 to up!
here is my gradle moudle code and there is no error!!`apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.milad_admin.counter"
minSdkVersion 9
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'])
compile 'com.android.support:appcompat-v7:23.2.1'
}
`

Cannot find <stdio.h> in android studio project

i am trying to run FM radio project in android sudio but it gives me error
(i downloaded this project from this git https://github.com/mikereidis/spirit2_free)
IMAGE : Android studio + Cannot find stdio.h
here is my gradle file settings
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.testFM"
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.4.0'
}
and here is the local.properties file where NDK path is declared
ndk.dir=C\:\\Users\\*****\\AppData\\Local\\Android\\sdk\\ndk-bundle
sdk.dir=C\:\\Users\\*****\\AppData\\Local\\Android\\sdk
Please help
Thanks
Try to run File->Invalidate Caches / Restart...

Error:(24, 0) Project with path ':wear' could not be found in project ':mobile'. Android Studio

I got the following error in Android Studio while creating project...
Error:(24, 0) Project with path ':wear' could not be found in project ':mobile'.
This is my build.gradle file code, I want to resolve this issue. Any help appreciated...
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.user.usereventdemo"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
wearApp project(':wear')
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
}
Looking at your settings.gradle, is it including :wear,?
if you don't want codes of wear, then delete :wear, and wearApp project(':wear') in your build.gradle.
if you want, then you have to find codes of wear, I'm afraid.
Under Gradle Scripts folder in Android Studio, locate "settings.gradle".
Open it and add ':wear' to the end of include statement.
It should look something like this:
include ':mobile', ':glass', ':wear'

Resources