[MUSIC PLAYING]
TIANYU GENG: So hello everyone.
My name is Tianyu.
I work on the Android Studio C++ support,
and today I'm going to talk about the new features in this
area.
So first, let's talk about the expanded GNI support.
GNI allows developers to call C or C++ function from Java
Kotlin.
And to do so, one simply declares an external function
in Kotlin or a native method in Java,
and then provides the implementation in C or C++.
Note that the signature and the name of this GNI function
definition must match the counterpart in Java and Kotlin
according to the DNI spec, otherwise you
get the runtime error.
So without the expanded GNI support,
the typical workflow looks like this.
You write your code, you build it,
you launch to the emulator or a real device,
and the app instantly crashes.
So you open up Logcat, and you probably see a unsatisfied link
error there.
Then you stare at your code, and you figure out, oh, there's
a typo.
Then you fix it.
Well, this whole process is frustrating
because the feedback loop is very long.
And now with the expanded GNI support,
the ID highlights error in real time
as you type, and sometimes even offers suggestions for you
to fix it automatically.
And this makes it much easier.
So for example, if you've forgot to provide a GNI implementation
for the native method, it highlights an error in Kotlin
now.
And here's another example where you have a signature mismatch.
You're providing an extra parameter
in the implementation, but it shouldn't be there.
And also the ID understands the connection
between the native method declaration and implementation,
so it offers navigation, reference search,
and refactoring support.
And also we implement type hint, so it's easier
to write your GNI code.
And also, all these features works with native function
that's bound through calling RegisterNatives in addition
to name mangling.
And the second thing you can do with GNI is manipulating Java
or Kotlin objects, methods, fields,
and arrays inside C or C++.
And this is achieved through calling special functions
defined in the GNI.h header file that's part of the Android NDK.
Again, without the expanded GNI support,
this workflow is frustrating.
And we're here to help with more static checks.
So for example, we implemented completion and inspection
for the parameters of FindClass call,
and similarly for GetMethodID, where
we complete the method name and type for you,
and again, similarly, for FieldID.
We also implement specific checks
that is custom to these [? method ?]
of these special functions in the GNI header.
So for example, here since we're calling the charat method
from string class--
but this method returns a char, so the right [? flavor ?]
to call here is call char method rather than call bully method.
And this is a mistake, and the IDE knows about it.
And here's another example.
We're performing more checks on the parameters even
for CallCharMethod.
In this case, char add expresses one parameter,
but we're passing it two.
And lastly, the IDE now understands the connection
between the string [? literacy ?] passed
to find class, get method ID, and get field ID,
and establishes the connection between that
and the corresponding Java or Kotlin symbols.
So again, navigation, reference search, and refraction
just works.
And now one more thing I want to talk about
is APK debugging reload.
So what is APK debugging?
Some developers use other tools than Android Studio
to build their apps, but they still
want to debug with Android Studio,
and APK debugging is for them.
They can open the APK directly in Android Studio
and start a debugging session there.
So previously, without APK debugging reload,
the workflow looks like this.
Every time the developer creates a new build of their APK,
they have to reimport it manually and configure
the debugging symbols and source code so that the source
code can show up in the IDE.
Now with the APK debugging reload,
the IDE picks up the changes of the APK on the file systems
automatically, so users don't have
to go through that configuration process over and over again,
and this helps the user iterate much faster.
That's it for what's new in Android Studio C++ support.
Thank you for your attention, and enjoy
the rest of Android Dev Summit.
[APPLAUSE]
[MUSIC PLAYING]