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

Add Android Linting Example #3931

Open
wants to merge 39 commits into
base: main
Choose a base branch
from

Conversation

c0d33ngr
Copy link
Contributor

This is meant to to be a draft of item number 4 of issue #3868. The android linting

Hi @lihaoyi is this close to what you have in mind about the android linting or there's more?

@lihaoyi
Copy link
Member

lihaoyi commented Nov 10, 2024

@c0d33ngr looks good, need to include an example test and explanation so we can include it in the documentation

@himanshumahajan138
Copy link
Contributor

himanshumahajan138 commented Nov 10, 2024

@c0d33ngr Buddy you did just basic linting but this is not the appropriate way tbh i have tried this on my example and its saying the miss of class file but class files only come after the compilation

so @lihaoyi i request you to please wait till my new pull request(anndroid bundle support) gets merged coz in that i have updated the whole android app building process and made it professional (now we can include custom resources)

so @c0d33ngr sorry to interrupt you, but please understand...

@lihaoyi
Copy link
Member

lihaoyi commented Nov 10, 2024

@himanshumahajan138 completing bounties out of order is fine. I'll look at your PR if you wish and we can decide which one to merge first

@himanshumahajan138
Copy link
Contributor

@himanshumahajan138 completing bounties out of order is fine. I'll look at your PR if you wish and we can decide which one to merge first

Ya I Agree We can decide which one to merge first

i was saying before becoz there will be need for updated code as you can see in my pr i have updated the codes with resources

so that's the only thing i was concerned about rest we can decide this...

@c0d33ngr
Copy link
Contributor Author

mill.javalib.palantirformat.PalantirFormatModule.formatAll java.nio.file.NoSuchFileException: /workspaces/mill/bsp/test/src
    os.walk$stream$.attrs(ListOps.scala:205)
    os.walk$stream$.apply(ListOps.scala:166)
    os.walk$.apply(ListOps.scala:96)
    mill.javalib.palantirformat.PalantirFormatModule$.$anonfun$palantirArgs$2(PalantirFormatModule.scala:177)
    scala.collection.Iterator$$anon$10.nextCur(Iterator.scala:594)
    scala.collection.Iterator$$anon$10.hasNext(Iterator.scala:608)
    scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:477)
    scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:480)
    scala.collection.Iterator$$anon$9.hasNext(Iterator.scala:583)
    scala.collection.mutable.ListBuffer.addAll(ListBuffer.scala:145)
    scala.collection.mutable.ListBuffer.addAll(ListBuffer.scala:39)
    scala.collection.mutable.Growable.$plus$plus$eq(Growable.scala:69)
    scala.collection.mutable.Growable.$plus$plus$eq$(Growable.scala:69)
    scala.collection.mutable.AbstractBuffer.$plus$plus$eq(Buffer.scala:314)
    mill.javalib.palantirformat.PalantirFormatModule$.palantirArgs(PalantirFormatModule.scala:180)
    mill.javalib.palantirformat.PalantirFormatModule$.palantirAction(PalantirFormatModule.scala:131)
    mill.javalib.palantirformat.PalantirFormatModule$.$anonfun$formatAll$2(PalantirFormatModule.scala:102)
    scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)

@lihaoyi this command below produce the error output above. What could be wrong?
I'm trying to lint java files
> ./mill mill.javalib.palantirformat.PalantirFormatModule/

@c0d33ngr
Copy link
Contributor Author

@lihaoyi @0xnm does the PR addresses the android linting example opened issue? What changes are needed if it doesn't?

@lihaoyi
Copy link
Member

lihaoyi commented Nov 10, 2024

@c0d33ngr the lint error should be fixed in latest main branch, if you merge in main it should work.

Give me some time to do a proper review, I'm not familiar with android haha

@c0d33ngr c0d33ngr changed the title [WIP] Android Linting Example Add Android Linting Example Nov 10, 2024
@c0d33ngr c0d33ngr marked this pull request as ready for review November 10, 2024 22:17
@lihaoyi
Copy link
Member

lihaoyi commented Nov 13, 2024

FYI I'm planning on landing #3935 first before coming back to this, since that one is a larger and more invasive PR so this one would be easier to rebase/merge after

@lihaoyi
Copy link
Member

lihaoyi commented Nov 13, 2024

Took a review pass. Looks like a straightforward change but left a few nits

@c0d33ngr
Copy link
Contributor Author

Took a review pass. Looks like a straightforward change but left a few nits

I'll do the necessary changes and also include more features to it. I had to rewrite it as a module after looking through java linting in the codebase and also other android related modules

@c0d33ngr
Copy link
Contributor Author

I was ill so I couldn't resolve the issues pointed out from code review on time but I'm good now

@lihaoyi
Copy link
Member

lihaoyi commented Nov 28, 2024

@c0d33ngr you'll have to figure it out. I'm not an expert in the Android toolchain and I won't have the ability to become one on short notice, so you'll need to learn enough about the toolchian figure out how to fit it into the Mill build convention

@c0d33ngr
Copy link
Contributor Author

Alright @lihaoyi

Found out the solution from the doc here

@lihaoyi
Copy link
Member

lihaoyi commented Nov 29, 2024

I think this looks good. @0xnm I don't know if you want to glance over this before I merge it

example/android/javalib/3-linting/build.mill Outdated Show resolved Hide resolved
example/android/javalib/3-linting/build.mill Outdated Show resolved Hide resolved
example/android/javalib/3-linting/build.mill Outdated Show resolved Hide resolved
scalalib/src/mill/javalib/android/AndroidLintModule.scala Outdated Show resolved Hide resolved
scalalib/src/mill/javalib/android/AndroidLintModule.scala Outdated Show resolved Hide resolved
@c0d33ngr
Copy link
Contributor Author

Hi @lihaoyi took a break off the issue fro sometime, now working on it

I want to ask how to use runClassapth() and sources() within another task

runClasspath().mkString(":").toString and sources().toStringdoesn't seem to work even though storing the path values in a variable and printing it out do displays the values

Got something like this as error

[1-61] Class path entry /workspaces/milling-two/3-linting/out/app/androidLintRun.dest/ref does not exist
[1-61] Source folder /workspaces/milling-two/3-linting/out/app/androidLintRun.dest/Vector(ref does not exist.
  // Specify additional flag options for Android Lint not defined in `AndroidLintModule`
  def androidLintArgs: T[Seq[String]] = Task {
    val cp = runClasspath().mkString(":").toString
    println(cp)
    val src = sources().toString
    println(src)
    Seq(
      "--classpath",
      runClasspath().mkString(":").toString,
      "--sources",
      sources().toString
    )
  }

@lihaoyi
Copy link
Member

lihaoyi commented Dec 10, 2024

@c0d33ngr runClasspath() returns a Seq[PathRef] IIRC, so you need to .map(_.path) to turn it into raw paths suitable for external programs. Same with sources()

@c0d33ngr
Copy link
Contributor Author

@c0d33ngr runClasspath() returns a Seq[PathRef] IIRC, so you need to .map(_.path) to turn it into raw paths suitable for external programs. Same with sources()

Okay thank you, trying it out

@c0d33ngr
Copy link
Contributor Author

@0xnm please review when less busy. I've done the changes you requested

Also, to make use of checkOnly, disable, enable and others in the mill Android lint, pass in the --check flag for specific checks in the androidLintArgs as it's done with --classpath and --sources in the linting example

checkOnly equivalent to android lint cli flag --check
disable equivalent to --disable
enable equivalent to --enable
And so on

@c0d33ngr c0d33ngr requested a review from 0xnm December 10, 2024 21:45
@c0d33ngr c0d33ngr requested a review from 0xnm December 14, 2024 10:08
@c0d33ngr
Copy link
Contributor Author

AndroidManifest.xml:4: Error: Class referenced in the manifest, com.helloworld.app.MainActivity, was not found in the project or the libraries [MissingClass]
        <activity android:name=".MainActivity"
                                ~~~~~~~~~~~~~
1 errors, 0 warnings

Hi @0xnm do you have any idea to why the lint cli tool couldn't spot the it?
I tried including generatedSources, compileClasspath but the lint doesn't seem to find the file it needed

@0xnm
Copy link
Contributor

0xnm commented Dec 14, 2024

I suggest you to check the arguments you are calling lint tool with and verify that your MainActivity.java file path is in the list of the sources passed.

@c0d33ngr
Copy link
Contributor Author

I suggest you to check the arguments you are calling lint tool with and verify that your MainActivity.java file path is in the list of the sources passed.

Okay... I'll look into that

What think of the PR any changes needed?

@c0d33ngr
Copy link
Contributor Author

Hi @0xnm , the suggestion you gave work. It was the sources() path. The --sources flag expect millSourcesPath + /src/main/java/ and not millSourcesPath + /src

You can review when less busy

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.

4 participants