I'm new to Android programming and new to Studio (0.4.4). For the first time, I found a class I wanted to incorporate into my project. Per other SO advice here, I created a new module by the same name, then replaced the Java template with the new class. So far so good.
Unfortunately, while it could find and import the java.* classes, it cannot find and import any of the android.* classes, specifically android.os.SystemClock and android.util.Log. (e.g., "Cannot resolve symbol 'X'") What steps do I need to take so that they can be found and imported? Thanks for any help.
Updated build.gradle:
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:+'
}
If you want to use Android classes in a module, it needs to be an Android module. The build.gradle file needs to specify:
apply plugin: 'com.android.library'
And you may also need:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
though newer projects are built from a template that includes this in the top-level build.gradle file and it's not necessary to specify it again below; try without and see if it complains or not.
In any event, with an android-library
module type, you'll need an AndroidManfiest.xml file and the associated trappings of an Android project -- resource directories and the like. This is probably what you want -- that way if your library has resources or additions to the manifest file, they will get properly merged at runtime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With