0

I get this error compiling java sources into classes using javac.

There's the only layout for MainActivity in the res folder, I generated R.java with aapt2 and imported it.

I used the following to create R.java:

aapt2 link --manifest AndroidManifest.xml -I android.jar -R co/layout_activity_main.xml.flat --java 

And here are the errors that I am getting.

javac it/dummy/MainActivity.java -cp knoxsdk.jar:android.jar:it/
it/dummy/MainActivity.java:12: error: cannot find symbol
import it.dummy.R;
               ^
  symbol:   class R
  location: package it.dummy
it/dummy/MainActivity.java:19: error: package R does not exist
        setContentView(R.layout.activity_main);
                        ^
it/dummy/MainActivity.java:21: error: package R does not exist
        final Button activateBtn = findViewById(R.id.activateBtn);
                                                 ^
it/dummy/MainActivity.java:29: error: package R does not exist
        final Button installBtn = findViewById(R.id.installBtn);
                                                ^
it/dummy/MainActivity.java:37: error: package R does not exist
        final Button updateBtn = findViewById(R.id.updateBtn);
                                               ^
5 errors
Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
cenotaMe
  • 9
  • 2
  • 2
    This question has nothing to do with [R](https://en.wikipedia.org/wiki/R_(programming_language)) - edited tag. Q: Why the heck are you running aapt2 manualy? If you 1) Created the project with Android Studio, 2) DELETE `import it.dummy.R;` from your .java source, then finally 3) build with Android Studio - does everything "just work"? – paulsm4 Nov 09 '19 at 22:33
  • Your title and your question do not agree. Different error messages. – user207421 Nov 10 '19 at 02:43

2 Answers2

1

I assume that R.java is in it/dummy/ and that MainActivity.java has package it.dummy;. What appears to be wrong is the classpath: should contain '.' instead of 'it/':

javac it/dummy/MainActivity.java -cp knoxsdk.jar:android.jar:.
sgerwk
  • 11
  • 1
0

I think you need to compile your resource first in order to link them later with the link option as follows.

aapt2 compile -o co/res/ app/src/main/res/layout/layout_activity_main.xml

Also please see this answer for other options.

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
  • 1
    You're correct: one needs to *COMPILE* the layout resource before one "links* it. But it still begs the question: Q: *WHY NOT JUST USE ANDROID STUDIO*??? And related question: why put Android standard "R" in a non-standard place like "it.dummy"??? – paulsm4 Nov 11 '19 at 17:02
  • @paulsm4 LOL. I don't know, everybody has their own reasons. – Reaz Murshed Nov 11 '19 at 17:29