Android Studio w/gradle: Package r does not exist
I'm a novice Android developer trying to convert an Android Studio project
that does not currently use Gradle (and compiles and runs just fine) to
one that uses Gradle on OS X. I'm stuck on a Resource error, which I think
may have to do with either my project structure, settings in the IDE,
settings in the build.gradle files, or some combination of those.
The way I went about doing the conversion was to first create a new
project in Android Studio, copy over files to appropriate locations, then
add some settings in the IDE and build.gradle files. My resulting project
structure is,
„¥„Ÿ„Ÿ frontlinesms-for-android
„¥„Ÿ„Ÿ build.gradle
„¥„Ÿ„Ÿ gradle
„¥„Ÿ„Ÿ gradlew
„¥„Ÿ„Ÿ gradle.bat
„¥„Ÿ„Ÿ local.properties
„¥„Ÿ„Ÿ lib
„¤„Ÿ„Ÿ lib1.jar
„¤„Ÿ„Ÿ lib2.jar
„¤„Ÿ„Ÿ ...
„¥„Ÿ„Ÿ frontlinesms-for-android.iml
„¥„Ÿ„Ÿ FrontlineSMS
„¤„Ÿ„Ÿ build.gradle
„¤„Ÿ„Ÿ src
„¥„Ÿ„Ÿ main
„ „¤„Ÿ„Ÿ res
„ „¤„Ÿ„Ÿ AndroidManifest.xml
„ „¤„Ÿ„Ÿ java
„ „¤„Ÿ„Ÿ net
„ „¤„Ÿ„Ÿ frontlinesms
„ „¤„Ÿ„Ÿ android
„ „¥„Ÿ„Ÿ FrontlineSMS.java
„ „¥„Ÿ„Ÿ ...
Most notably, maybe, is I put the res/ folder at the same level as java/
and AndroidManifest.xml. I'm trying to follow the conventions mentioned in
the Gradle Plugin User Guide so I don't have to customize too much in the
build.gradle files.
I also marked the folder FrontlineSMS/src/main/java/net as source because
if I don't then nothing attempts to compile. I created a new build.gradle
file in FrontlineSMS/build.gradle because it did not exist when I made the
new project, even though an instructional video on the Gradle website said
it would.
In the IDE I also set the dependencies for the external libraries I have
in /lib.
When I try to compile via the IDE I get many Package r does not exist
errors, indicating the auto generated R class is not getting generated or
recognized. This is defined in the project as,
import net.frontlinesms.android.R;
in several files. What can I do to make Android Studio / Gradle recognize
the resources I have defined under src/main/res?
Reading up on others' questions, I notice that some solutions to this
error involved marking a "gen/" folder as a source root or "cleaning" the
project. I tried creating a gen/ folder in the root directory and marking
it as source but that didn't work. And, rebuilding the project just gives
me the same errors.
My root build.gradle file has the following,
dependencies {
compile project(':FrontlineSMS')
}
And the one under FrontlineSMS/build.gradle has,
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile file('lib/acra-3.1.1.jar')
compile file('lib/activation.jar')
compile file('lib/additionnal.jar')
compile file('lib/annotations.jar')
compile file('lib/libGoogleAnalytics.jar')
compile file('lib/mail.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
When I try to build from the command line using ./gradlew clean I get this
error,
FAILURE: Build failed with an exception.
* Where:
Build file
'/Users/rhawkins/workspace-studio/frontlinesms-for-android/build.gradle'
line: 3
* What went wrong:
A problem occurred evaluating root project 'frontlinesms-for-android'.
Project with path ':FrontlineSMS' could not be found in root project
'frontlinesms-for-android'.
In addition to my previous question, I'd appreciate any tips you can lend
as to how this project should be structured. This is not meant to be a
multi-project setup. Thanks for your help.
No comments:
Post a Comment