我有一個在Eclipse中創建的Android項目exported as Gradle build file,然後在Android Studio中打開。 (是的,在AS中創建一個乾淨的項目會容易得多,但我需要支持當前的項目結構。)如何使Android Studio正確讀取(minSdkVersion)AndroidManifest.xml?
否則,現在大多數情況下都在工作,但仍有一些東西需要解決。 在每一個活動類,顯示了這個錯誤:Class requires API level 1 (current min is -1): Activity
Alt + Enter鍵報價以修復與@TargetApi
註解......但爲什麼我應該做的是,在AndroidManifest.xml
的時候,我們有:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
AndroidManifest.xml
位於項目根目錄(Eclipse默認?)。看起來像Android Studio不能正確讀取其中的設置。該項目仍然編譯好。
任何想法如何擺脫錯誤?
Eclipse的生成build.gradle
看起來是這樣的:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
呀,重新打開項目後,這個固定。謝謝! – Jonik