I Like Walls03 Aug 2017 | Comments | tags: android instant apps
I have always been told I’m stubborn. And I am. So jumping off this post, I continued doing instant apps stuff and I learnt more things this week.
- More than I figured last week, data binding is broken. As in broken broken. Do not use AS3.0 Canary 9 if you want to look at multi-feature instant apps and your data binding files will NOT be in the base module.
- I seemed to have hurt AAPT2’s feelings. It seems to have a vendetta against me. First it was complaining of (insert eyeroll) 9-patch image errors, then it became Manifest errors, and then I gave up and turned it off again. To do that, add
- BUT! If you are doing the thin feature approach described in my previous post, AAPT1 fails if your instant app has multiple features. Remember that for multi-feature instant apps, common resources should be in a
base featuremodule. That means your library which your feature depends on (which in turn depends on the
base feature) does not have access to any of the things declared in
values.xmland such. I filed a bug for this, please star!
- There are a lot of improvements in AS3.0, but there are also some caveats. To test an instant app in the emulator, you have to run it from Studio (
adb installfor an instant app DOES NOT work – AS will install it as a full app). You can (should?) use
adb install --ephemeral FEATURE_APK1 FEATURE_APK2 FEATURE_APK3on an O device (but there is a bug on O emulators so YMMV)
- Set your run configuration to launch a URL. If AS won’t let you change the default launch options, delete the configuration and make a new one
- Signing configs need to be in all feature modules. Once that’s defined, absolutely do not forget to reference it in your build types!!
I haven’t figured out everything, so it is very likely that I will have more of things to say!
'I will just migrate this real quick', said no one ever28 Jul 2017 | Comments | tags: android instant apps
When Android Studio 3.0 was announced at I/O, I was very keen to try it out. Mostly because of all the cool stuff in it, but also because of more support for instant apps.
We want to continue supporting our instant app, so I thought it’d be a worthy investment to get a headstart and migrate our EAP version to the post-I/O SDK 1.0 version.
Two months later and I am still migrating. 😅
If you are in the same boat as I am (or maybe you are starting out with instant apps?) here are some of the things I have learnt so far:
- Android Studio 3.0 threw its hands up when I opened our pre-v1.0 version of the app. It refuses to acknowledge that there used to be a
- Butterknife works with Android applications and Android libraries, but not with
com.android.feature(henceforth referred to as
- To go around the Butterknife issue, you can put all your code in a
featuremodule would then declare this library as a dependency and nothing else. Ben calls this the thin module.
- However, if you use data binding in your instant app, the thin module approach will not work by default. And by not work, I mean it will complain of not being able to find an object you use in your data binding files if that object comes from some other module.
If I have this in a data binding file:
<variable name="media" type="com.fairfax.domain.base.model.Media"/>
it will complain that:
/Users/zarah.dominguez/Android/.../src/main/res/layout/item_gallery.xml Error:(27, 35) Cannot resolve type for media
Mediais in another module called
- Remember that with the new Android Gradle plugin, dependencies do not bubble up automatically. What I opted to do here is to make my
implementation. You can stick with
implementationbut make sure you include the full list of depedencies in your
featuremodule as well.
- Make sure you enable data binding everywhere. As in everywhere. As in all
build.gradlefiles in all modules required by your instant app.
- I am not quite sure yet if it is a bug or an intended behaviour with
featuremodules, but Manifest merger seems to behave differently that with an
application. To fix the issue of Android Studio complaining that there is no default Activity, move your instant app entry point activity declaration (and all the intent filters it requires) into the
- If you want to test using the emulator, create an image that does not have the Play Store. The Pixel should work fine. Remember to log in with a Google Account and to opt in to instant apps!
PS: At one point I gave up on this and shelved the migration for several weeks, hence the “still going on” thing.
PPS: No idea what I am blabbering on about? I talked to Kaushik and Donn about instant apps on Fragmented!
Children, Respect Your Parent(s)21 Jun 2017 | Comments | tags: android quick tip
I was updating a bit of code the other day that involved dynamically inflating views into a
DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.row_related_property, container, false).
I decided to jump in and update it to use the generated binding’s inflate method:
This inflated layout has margins set on it’s root, similar to this:
<LinearLayout android:orientation="vertical" android:layout_marginTop="16dp" android:layout_width="match_parent" android:layout_height="wrap_content"> <!-- more views here --> </LinearLayout>
Happy with my changes, I ran the app and immediately noticed a problem. All the views are smooshed together! Show layout bounds tell me that there is no margin being set at all.
My first thought was that generated binding inflation behaves differently. Odd. I looked through the code and it seems to call through to the same method. Weird.
With a little help from my friends (holla Hugo!), I was quickly pointed out the error of my ways. It is important to respect your parent(s)! And by respect I mean pass it on into
RowRelatedPropertyBinding.inflate(LayoutInflater.from(context), container, false);
One thing I always forget is that any
layout_* attribute is an instruction to the parent. Whenever I am reminded of this, I always go “Ah yes of course I knew that”.
The code that generated the screenshot above is in my Sandbox repo.
If you want to read more about views, layouts, and attributes, go ahead and read Ian Lake’s excellent Medium post on the topic.