简体   繁体   中英

How do I resolve .class-related file not found errors in Android Studio on compile?

I'll admit that I'm pretty stumped. I've taken over a project at work and it's a very simple Android application with very few dependencies. Building should be a cinch, but I'm using Android Studio and I'm new to it. At compile-time, I'm getting the following errors and I'm not sure what they mean. How can I resolve these error so I generate a build I can deploy to a device?

Information:Using javac 1.6.0_65 to compile java sources
Information:Compilation completed with 8 errors and 0 warnings in 2 sec
Information:8 errors
Information:0 warnings
Error:java: /bin/com/example/android/R$attr.class (No such file or directory)
Error:java: /bin/com/example/android/R$drawable.class (No such file or directory)
Error:java: /bin/com/example/android/R$id.class (No such file or directory)
Error:java: /bin/com/example/android/R$layout.class (No such file or directory)
Error:java: /bin/com/example/android/R$string.class (No such file or directory)
Error:java: /bin/com/example/android/R.class (No such file or directory)
Error:java: /bin/com/example/android/BuildConfig.class (No such file or directory)
Error:Android Packager: [ExampleApplication] java.io.FileNotFoundException: /bin/ExampleApplication.unaligned.apk (Permission denied)

Just so you know, I did a Rebuild (same as Clean and Build?) in Android Studio and this is my output.

Error:Android Packager: [ExampleApplication] java.io.FileNotFoundException: /bin/ExampleApplication.unaligned.apk (Permission denied)

Are you sure that android studio can write in this directory ? you try executing android studio as Administrator ?

So, this was apparently a user error (read: I did something stupid) rather than a problem with the software. However, I'll share my experience for others out there.

There are a couple of path spots you might care about in Android Studio. The first is the "Project Compiler Output" and it's under Project Settings. Under the Module Settings, each module has a "Paths" tab where you can specify compiler output directly.

I was doing two things (well, three really) wrong. 1) I hadn't set the Project Compiler Output and 2) I was setting the Module > Paths > Compiler Output to "/bin/classes" which was going to the hard drive root. This is not a relative path and needs explicitly set. UNLESS, you just check "Inherit project compile output path" and then make sure you set your project's "Project Compiler Output."

The third thing I didn't do was mark my /src folder as a "Source" under the "Sources" tab. Also, don't forget to mark any jars you're including as libraries!

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM