Office Hours — Today, June 2

Friday, May 29

Jun 2
8:55 AM
Mark M.
has entered the room
Mark M.
turned on guest access
CodeApprentice
has entered the room
Mark M.
hello, CodeApprentice!
how can I help you today?
CodeApprentice
Good morning.
I'm trying to set up UI Automator 2.0 in an existing project in Android Studio 1.2.1.1.
the IDE gives me "Warning:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (22.2.0) and test app (22.0.0) differ."
Bryan
has entered the room
Bryan
Hello
Mark M.
(BTW, hello Bryan, I will be with you in a moment!)
Bryan
sounds good
9:00 AM
Mark M.
CodeApprentice: what are "app" and "test app"?
CodeApprentice
my dependencies
I don't understand your question.
Mark M.
your error cites "Resolved versions for app (22.2.0) and test app (22.0.0) differ."
does the name "test app" ring any bells?
CodeApprentice
no, I believe that's a generic name for the code under androidTest.
I'm using the "new" gradle project structure
Mark M.
ah, OK
kinda confusing -- they should be citing something like androidTest there
CodeApprentice
yah, the error message is unclear in lots of ways
Mark M.
anyway, you'll probably want to run a Gradle dependency report
gradle dependencies
Bill M.
has entered the room
Mark M.
run at the command line
CodeApprentice
./gradlew :app:dependencies isn't very helpful...it gives the same error.
Mark M.
(BTW, hello Bill, I will be with you in a bit, after CodeApprentice and Bryan!)
well the dependency report should show you who is asking for what
Bill M.
Yep! No problem. Thanks Mark. Hello all.
Mark M.
one of your direct dependencies wants 22.2.0 of support-annotations, the other wants 22.0.0
you need to determine who wants what, so you can add exclude directives in the Gradle build file, to eliminate the requirement for the older one, and then hope it all holds together
or, perhaps you can raise the version of the direct dependency that is looking for 22.0.0 to something higher, one that will be happy with 22.2.0
CodeApprentice
From http://stackoverflow.com/questions/29857695/and... it looks like the conflict is between the dependencies of `com.android.support.testrunner0.2` and `com.android.support:support-v4:22.1.0`
Mark M.
well, that emoji is a first for this chat... :-)
9:05 AM
CodeApprentice
and that emoji is supposed to be the word "runner"
Mark M.
hah!
CodeApprentice
ahh...the colon separator turned it into an emoji
Mark M.
anyway, either you need to synchronize the direct dependencies, or exclude the older 22.0.0 transitive dependency and hope that the library that wanted it will be happy with 22.2.0
let me take questions from the others, and I'll be back with you in a bit
Bryan: your turn! do you have a question?
Bryan
yes
I have 2 questions the first has to do with "Fragment already added" errors I am getting. We are doing a single activity app that manages fragment "ups" synonmous with "back". We are getting this error at "random" (meaning I can't reproduce reliably yet) times. (crash = http://pastebin.com/wzuA7xiQ). What I am confused about is that we first try to find a fragment by tag and then use that otherwise we create a new one and then we just use .replace(). How can hitting "back" add a fragment that has already been added?
Mark M.
how are you creating a new one? are you sure there isn't some logic in there that tries to recycle an existing instance?
CodeApprentice
sounds good. I'll be working on things on my end.
Bryan
when we navigat to new ones, we do try to recycle and use replacr
Mark M.
the error sure sounds like it is the existing HomeFragment instance that is trying to be added again
Bryan
this only happens on back
Mark M.
I don't mean your findFragmentByTag() call; are you holding onto HomeFragment anywhere?
Bryan
oh, meaning a memory leak of sorts?
9:10 AM
Bryan
if so, it is very possible
Mark M.
you might experiment with dump() on FragmentManager
Bryan
so if I have an instance of homefragment still being held by something and we hit back, it won't "reuse" the hoemfragment in memory, but will error out because it is?
(is held in memory)
Mark M.
well, I don't know all the ins and outs of your code
anyway, back to dump()
Bryan
yeah, how would you recommend using that?
Mark M.
I haven't played with it, but ideally it outputs the current contents of the FragmentManager
you might experiment with in the lab, to see whether the FragmentManager contents match your expectations
Bryan
Ok, interesting, I think i will focus first on trying to reliably duplicate the error and then see what is in dump on error vs not on error
Mark M.
and depending on what you are doing in production, when you catch this error, you might dump() the state and include it in some report to your server
Bryan
perfect, thank you!
Mark M.
let me take questions from the others, and I'll be back with you in a bit
Bryan
can I wait in line for my second question?
kk
Mark M.
Bill: your turn! do you have a question?
Bill M.
Ready?! :)
GCM related questions regarding Registration ID.
Can an OS update actually reset the system token, like a factory reset?
*Registration ID
Mark M.
beats me
Bill M.
lol
Mark M.
outside of what you see in the GCM chapter, I know diddly-squat about GCM
that being said, registration IDs seem to be twitchy, from what I've seen on Stack Overflow
Bill M.
Alright. No worries. I'll follow up with you when I get a response from the Googles :) Reaching out to their GDEs.
Thanks Mark.
9:15 AM
Mark M.
CodeApprentice: back to you! do you have another question?
CodeApprentice
still working on this
Mark M.
OK, I'll be back with you later
Bryan: back to you! do you have another question?
CodeApprentice
bill, are you working on the behavior of the back button (at the bottom of the screen) or the up/home button in the action bar?
Bryan
yes, it is already in stackoverflow, should I just paste link
or paste question?
Mark M.
link is probably better
Bryan
Mark M.
you are referring to the deep-linking stuff Google has been promoting, to allow search results to drive into an app?
Bryan
no
to the stuff they currently have to do deep linking, hang on I'll get link I used
it is really bizarre behavior
Mark M.
that's what I was referring to, actually
9:20 AM
Mark M.
not really
Bryan
I have never seen the ability to open 2 distince app instances
Mark M.
they are not two instances
they are two tasks
if I understand your question correctly, Chrome is properly launching your activity in a new task
whereas the other browsers are not
Bryan
yes
Mark M.
on Android 5.x, the title bar of the overview screen is driven by the task owner, if you will, which in this case would be the browser
but the thumbnail will be of the top-most activity in that task
and if they didn't open the link with new-task semantics, that'll be your activity
Bryan
is there a way to tell different browsers to launch in a new task or to force them to use chrome only?
for that particular link scheme
Mark M.
no and no, but you can control the task stuff through manifest entries
Bryan
what do you mean?
or, what specifically do you mean
CodeApprentice
Whenever you are ready, here's the relevent output of my dependencies: https://gist.github.com/codeguru42/64d284f54a7d...
Mark M.
I think setting the task affinity on your activity can help manage this
(CodeApprentice: after Bryan and Bill, I'll be with you)
Bryan
Ok, I can look into that, thank you
Mark M.
I'll need to work out a specific recipe for this and add it to the task chapter of the book
I had thought browser developers would always spawn these things in new tasks, if it's not being handled directly by their own app (i.e., a link to a regular Web page)
let me take questions from the others, and I'll be back with you in a bit
9:25 AM
Bryan
I need to ready up on tasks too, I am thinking in a different paradigm
9:25 AM
Bryan
ok
Mark M.
Bill: your turn! do you have another question?
Bill: if you have another question, chime in and let me know; for the moment, I'll focus on the others
CodeApprentice: so appcompat-v7 wants 22.2.0 of support-annotations, and runner wants 22.0.0
CodeApprentice
so how do I resolve the conflict?
Mark M.
change androidTestCompile 'com.android.support.testrunner0.2' slightly
beyond fixing the emoji
go androidTestCompile(...) { exclude module: 'support-annotations' }
where ... is the artifact string that gets emojified here in chat
and "go" is just a verb I used in the not-exactly sentence there
9:30 AM
Mark M.
AFAIK you need the parentheses to allow the closure syntax
the exclude line says "pay no attention to this transitive dependency"
you are filling that dependency elsewhere
now, there's a chance that this won't work, in that something in 22.2.0 breaks what runner wants from 22.0.0
in which case, you could try excluding support-annotations from appcompat-v7, to force the older edition, but that seems even more likely to have problems
and, if neither combination works, AFAIK, you're screwed
which is why runner really needs to be more flexible in its dependency requirement
CodeApprentice
one other option is to revert to an earlier version of appcompat-v7
Mark M.
that too
CodeApprentice
not ideal, but doable
Mark M.
though that has other ramifications, particularly since it's a GUI bit, so the older edition won't necessarily tint all the widgets you'd like
plus bug fixes and whatnot
CodeApprentice
and btw, yes, the parens are required.
Mark M.
let me take questions from the others, and I'll be back with you shortly
Bryan: your turn! do you have another question?
CodeApprentice
hmmm....still getting the same error. Maybe another of my recently added dependencies also depends on support-annotations...
Mark M.
(CodeApprentice: grep through the dependency report, I guess, seeing who else wants it)
CodeApprentice
working on that ;-)
9:35 AM
Mark M.
OK, it's free-for-all time -- if anyone has a question, go right ahead
Bryan
what is the best way to manage apk size?
Mark M.
exercise and eating right
:-)
Bryan
nice
Mark M.
could you be more specific?
I have a chapter on APK size tips in the book
and there's other stuff I need to add in there, like shrinkResources
Bryan
perfect, I will read both of those~!
Mark M.
again, if anyone has any question, go right ahead
Bryan
View paste
What do you think about this to "restart" app after an authentication change:
....
finish();
startActivity(new Intent(this, MyActivity.class));
...
Mark M.
that doesn't restart an app
9:40 AM
Bryan
sorry, acgivity
Bill M.
has left the room
Mark M.
it shouldn't be needed
just move your onCreate() and related code out to some other method
that you call from onCreate() and on an authentication state change
Bryan
hmmmm
that seems very simple and elegant
almost too easy
Mark M.
it'll also have less UI flicker
as we skip the activity transition
Bryan
I wonder if I had issues with the pulling the drawer stuff out of the oncreate? Authenticated there is a drawer, not so with unauthenticated
i will have to take a look, thanks
CodeApprentice
well, adding "exclude module: 'support-annotations'" still results in the same error. And I can't find anything in the dependencies report that shows another library with a transitive dependency.
Mark M.
would it be possible for you to post the whole report to another gist or something?
CodeApprentice
just support-v4 and runner depend on support-annotations
yah, I can do that
that's the one with the "exclude module"
9:45 AM
Mark M.
well, here's one possibility, rolling back to my original "app"/"test app" question
let's assume that "app" means the actual app and "test app" is the app with the androidTest sourceset included
your exclude stuff means that only one support-annotations will be used in each of those
however, the error message is complaining about the difference between "app" and "test app"
and, based on the reports, those do indeed differ
the test apps are using 22.0.0; the app is using 22.2.0
now, *why* the tooling would care, I can't say
CodeApprentice
so are you thinking that "test app" refers to the combination of both the main app and the androidTest stuff?
Mark M.
correct
CodeApprentice
hmm...
Mark M.
and that, for some reason, the tools want the dependencies to jive between the app and the test app
CodeApprentice
I see what you mean. In other words, the error message isn't very good.
Mark M.
actually, it's better than what I had been originally thinking, if my guess is correct :-)
"test app" isn't especially clear
9:50 AM
Mark M.
now, to fix this, you'd basically need to pin the regular and test editions of each build variant to the same support-annotations version
if nothing else, you'd exclude {} the transitive dependency from appcompat-v7 and runner, and manually require some version of support-annotations
though there may be some simpler Gradle syntax for handling this
CodeApprentice
Shouldn't excluding the support-annotations from runner be the same thing?
Mark M.
um, probably
to quote the old Infocom game Zork, "you are in a maze of twisty little passages, all alike" :-)
9:55 AM
CodeApprentice
hmm...https://code.google.com/p/android-test-ki... seems to be a bug report about this issue
Mark M.
yeah, resolutionStrategy was the simpler Gradle syntax that I was thinking of
basically, a single place to pin the version of a particular transitive dependency
CodeApprentice
trying that now
Mark M.
we are running out of chat time -- now's a fine time to get any last questions in!
Bryan
Is there a way to get a transcript of this emailed to me?
Mark M.
no, but you can view one at https://commonsware.com/office-hours/ shortly after the chat ends
Bryan
ok, great, thanks!
CodeApprentice
well, the resolutionStrategy worked...now to figure out the next error message.
10:00 AM
Mark M.
well, it's good to know that you're making progress
and with that, that's a wrap for today's chat
CodeApprentice
I'll bump an SO question and/or be back for the next office hours.
thanks for your help!
Mark M.
the next one is Thursday at 4pm US Eastern
you are very welcome
have a pleasant day, all!
CodeApprentice
has left the room
Bryan
has left the room
Mark M.
turned off guest access

Friday, May 29

 

Office Hours

People in this transcript

  • Bill Mote
  • Bryan
  • CodeApprentice
  • Mark Murphy