Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix examples/android code to actually run successfully #443

Merged
merged 1 commit into from
Jan 26, 2021

Conversation

nkoroste
Copy link
Collaborator

@nkoroste nkoroste commented Jan 5, 2021

Changes:

  • Add a manifest with a main activity to launch
  • Use ${lib_name} manifest variable in order to reuse the same manifest from multiple libs and inherit the right MainActivity from the right lib
  • Define resource_files attr to actually include the resource dir. Modify the code to actually use the resources.
  • Fixed the code to extend from AppCompatActivity in order to actually use androidx.appcompat and not crash on launch
  • Renamed lib target to my_kt and lib2 to my_android in order to make it easier to distinguish between the generated output files during debugging.
  • Added my_java target to help with debugging when comparing target output file generation for java vs native android vs kotlin
  • Added .bazelproject file for IDE

import android.os.Bundle
import android.widget.Button
import android.widget.LinearLayout
import android.widget.LinearLayout.LayoutParams
import androidx.appcompat.app.AlertDialog
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We leaned on appcompat to ensure it was included as part of the build.

Can you add something that requires it?

Copy link
Collaborator Author

@nkoroste nkoroste Jan 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This androidx.appcompat dialog never actually worked properly, it crashed on runtime with:
You need to use a Theme.AppCompat theme (or descendant) with this activity.
I fixed it though so that we are able to use androidx.appcompat properly

@@ -8,6 +8,9 @@ android_binary(
incremental_dexing = 0,
manifest = "src/main/AndroidManifest.xml",
multidex = "native",
manifest_values = {
"lib_name": "lib",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these depend on the binary name rather than a dependency? This feels closer to how it would actually be used - the libraries have their own manifests. Right now you also still have two binaries with the same package name (app and app3) as they both define this as lib.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well no, this variable is used to inherit the right entry main activity which is currently inherited from the library package name since this binary target doesn't actually have any sources. For both app and app3 the same lib is used so it inherits the same MainActivity which is fine.

I guess the more proper fix which will resemble reality better is to have a unique AndroidManifest.xml per android_binary target which I'm happy to do if you think it's worth it?

@nkoroste nkoroste force-pushed the nk-fixAndroidExamples branch from c19698b to 2ec60f9 Compare January 21, 2021 01:54
@google-cla
Copy link

google-cla bot commented Jan 21, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

- Add a manifest with a main activity to launch
- Use ``${lib_name}`` manifest variable in order to reuse the same manifest from multiple libs and inherit the right `MainActivity` from the right lib
- Define `resource_files` attr to actually include the resource dir. Modify the code to actually use the resources.
- Fixed the code to extend from `AppCompatActivity` in order to actually use `androidx.appcompat` and not crash on launch
- Renamed `lib` target to `my_kt` and `lib2` to `my_android` in order to make it easier to distinguish between the generated output files during debugging.
- Added `my_java` target to help with debugging when comparing plugin generation for java vs native android vs kotlin
- Added `.bazelproject` file for IDE
@nkoroste nkoroste force-pushed the nk-fixAndroidExamples branch from 2ec60f9 to 0d579e7 Compare January 21, 2021 01:57
@nkoroste
Copy link
Collaborator Author

@googlebot I consent.

@restingbull restingbull merged commit ddf4f18 into bazelbuild:master Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants