I want to use data binding in my android studio project if its available in production. I am searching online and find references to a beta copy which I clearly dont want. But i read here that data binding is apart of api 23 and built into android studio ? how do i use it if this is true ? I cant find it on jcenter, is it something thats built into the IDE ?
I created a minimum sdk project of 21 and I'd like to use databinding. This code in xml wont compile:
<TextView android:text="#{user.name}"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:visibility="#user.isAdmin ? View.VISIBLE : View.GONE}"/>
the exact error is on the visibility line and it says "Missing /"
Does it only work on api 23 ? wouldn't this break on older devices then ?
I am searching online and find references to a beta copy which i clearly dont want.
It is in a release candidate state at this time.
But i read here that data binding is apart of api 23 and built into android studio ?
Data binding is supplied by the Android Support libraries and a Gradle plugin. It is not related to API Level 23. Android Studio support exists, to some degree.
This code in xml wont compile:
That is because you are missing the binding expression opening characters. Change that attribute to:
android:visibility="#{#user.isAdmin ? View.VISIBLE : View.GONE}"
Does it only work on api 23 ? wouldn't this break on older devices then ?
Quoting the documentation: "you can use it with all Android platform versions back to Android 2.1 (API level 7+)."
The Data Binding Library offers both flexibility and broad compatibility—it's a support library, so you can use it with devices running Android 4.0 (API level 14) or higher.
However data binding is supported on Android Plugin for Gradle version 1.5.0 and higher.
I recommend you to use the latest Plugin for Gradle in your projects.
to get started with data binding see https://developer.android.com/topic/libraries/data-binding/start.html
Related
My library project has a location service, and per Android Q requirements it sets the android:foregroundServiceType="location" attribute in the manifest. When an app module uses my library and compiles against API level 28, it fails with the following error:
AndroidManifest.xml:57: AAPT: error: attribute android:foregroundServiceType not found.
How can my library maintain compatibility with older versions, while making sure the functionality works on Android Q?
I had same error and after migrating to Androidx and updating compileSdkVersion from 28 to 29 my issue was resolved. So please do these changes and you can get your solution
My goal is to avoid breaking anyone's build when the library version is updated, and at the same time avoid forcing the developer to compile against API 29. It seems I have two choices:
Provide a separate library so that developers compiling against API 28 and lower don't get impacted;
warn developers targeting the new version to replace the service definition in the manifest using tools:node="replace".
The problem with the first approach is that I will need to maintain two libraries for some time. The problem with the second is that developers must remember to revert the change once they update the SDK version.
In my case, I will go with the second approach. By passing an explicit foreground service type to the startForeground method when targeting Android Q, I can cause a crash if the type is not set in the manifest. The developer can therefore catch this when targeting Android Q and revert the manifest change to fix it.
I have an Android Xamarin appliation with android:minSdkVersion="15" and android:targetSdkVersion="21". Turned out that IDE (xamarin studio, visual studio) and compilation process just ignore if I'm using something above API 15 which is not expected behavior here.
For example there is a method Path.addArc(float,float,float,float,float,float) from API 21 and I was able to use it with the manifest settings above which gave me a run-time error NoSuchMethodError.
There is an easy fix to use an overload Path.addArc(RectF,float,float) from API 1 but my question is more about how to get a compile time error instead or a run-time.
[UPDATE]
Basically I want to maintain the backward compatibility for API 15 (minimum android version) while having API 21 as a target android version. And I want to get an IDE support when I'm trying to use any method above API 15. That means I need a warning saying that I'm using a method which doesn't exist in the minimum android version defined so please do a run-time version check.
Is it possible?
To get compile time warnings you need to set your Target Framework to the min SDK you want to support. This will give you errors when you try to use higher level apis. Open Project Options dialog. In this dialog, click Build > General
You can read about api levels here https://developer.xamarin.com/guides/android/application_fundamentals/understanding_android_api_levels/#Target_Framework
If you just want to get an error while keeping the target framework the same you can modify your IDE preferences to throw a compile time error vs a warning.
Our Xamarin.Android app is targeting Android 4.4 due to hardware constraints. The initial solution was created targeting API 23 and was downgraded. The above error is thrown after downgrading. The code referenced by the error is as follows:
<include layout="#layout/abc_screen_content_include"/>
<android.support.v7.widget.ActionBarContainer
android:id="#+id/action_bar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
style="?attr/actionBarStyle"
android:touchscreenBlocksFocus="true"
android:gravity="top">
<android.support.v7.widget.Toolbar
android:id="#+id/action_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:navigationContentDescription="#string/abc_action_bar_up_description"
style="?attr/toolbarStyle"/>
<android.support.v7.widget.ActionBarContextView
android:id="#+id/action_context_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:theme="?attr/actionBarTheme"
style="?attr/actionModeStyle"/>
</android.support.v7.widget.ActionBarContainer>
This error was replicated after creating a new solution targeting API 19 Android 4.4.
How do I remedy the above error?
Hit this in Xamarin Forms Project. Got this lovely:
"No resource identifier found for attribute 'touchscreenBlocksFocus' in package 'android' App1.Droid C:\dev\xamarin\dev\HWVFromScratch\App1 App1.Droid\obj\Debug\resourcecache\C6193E5D3119528BCA215B6037E272DE\res\layout\abc_screen_toolbar.xml"
To squarely target KitKat
Go into your Droid project properties
Set "Compile using Android Version" to "Use Latest Platform"
Set Minimum Android to Android 4.4( API Level 19 - KitKat )
Set Target Android version to Android 4.4 ( API Level 19 - KitKat )
Compiled like a champ. Screenshot of settings below...
This basically means that the Google tool aapt which is used to compile resources for your app doesn't know how to handle the touchscreenBlocksFocus attribute used somewhere in your resources (or in this case likely in the resources contained in the Android Support Libraries).
First it's worth reviewing my blog post explaining the various places API Levels are used in Xamarin.Android apps: http://redth.codes/such-android-api-levels-much-confuse-wow/
So in this case, your project's Target Android Version is what Xamarin.Android is passing to aapt as the API Level to build resources against.
This means you'll need to set your Target Android Version to a higher API Level (4.4 won't cut it) which understands the resource attributes you are using.
Of course, just because you change your Target Android Version doesn't mean you can't still have a lower Minimum Android Version specified, and your app can then still run on older API Levels.
Finally, it's generally best practice to set your Target Framework Version and Target Android Version to use the Latest SDK version available to avoid these types of issues. Then, set your Minimum Android Version to a lower API level if you wish. Of course you'll have to be aware of the API's you are using and that you take appropriate steps to gracefully avoid using API's that aren't available on a given version of Android at runtime.
It's been a month, but I would like to try and answer your question with the solution I had.
The problem I ran into was that I attempted to use Xamarin.Forms instead of functions/commands/API from the standard Android libraries.
One of the ways to install Xamarin.Forms is to use nuget - which I did. This however caused all kinds of problems, one of which you are experiencing.
So in order to stop these errors I had to remove several dependencies/references within the Xamarin Project by going to Project -> Edit References -> and on the right hand side of the window removing any Xamarin.XXXXX you might see starting with the obvious Xamarin.Forms and working your way through until you can finally compile your project successfully again.
While this was an answer to my similar issue, if you absolutely have to use Xamarin.XXXXX then this won't fix your issue as you are going to have to use the tools supplied by Android.XXXX.
I research material design project for 4.x API, It seem too many problems in style values, always style.... (in v-21) not found. I think v-21 is only build with api 21. But I want to build for 4.x API, do anyone know problem?
Here is some project in Github i found:
https://github.com/wasabeef/awesome-android-ui
https://github.com/rey5137/material
I use eclipse too. Change ANdroid API 21,22,23 but it still not work
The Log say : no resource found that matches the given name "TextAppearance.Appcompat.Body1"
Here is my picture:
OTHER QUESTION:
The Author say this material project can run on API 2.x -> 4.x , but why it need to build with API 21 -> 23? So can lower device can run it?
Set compileSdkVersion 23 or 21 or above in your build.gradle file.
The Log say : no resource found that matches the given name
"TextAppearance.Appcompat.Body1"
This is because you might not have imported AppCompat Library to your Eclipse Project.
The Author say this material project can run on API 2.x -> 4.x , but
why it need to build with API 21 -> 23? So can lower device can run
it?
Yes, Its always a good practice to build your App with the latest API version as this will include all the updated resources which might be not available in previous versions of Android. However, this will not affect your APK size in anyways.
I integrated AdMob in my app using Eclipse Juno - it is working fine. But when I tried to integrate it using Android Studio, I get this error:
Error: String types not allowed (at 'configChanges' with value 'keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize').
I also added jar file in libs folder. I use minSdk =9 and targetSdk=18. I also changed project.properties file to "target=android-13".
screenSize and smallestScreenSize were only added in API 13. See http://developer.android.com/guide/topics/manifest/activity-element.html#config
I presume you are getting this error when building the app? Change your build config so that you are building against version 13 or up of the SDK.
Check your target api level and minimum api level. i had similar issue before and i solved it like this:
target api level = highest available
minimum api level = 9
I dont know much about Android studio but you can do it from manifest.xml
i hope it helps.