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
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:.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.