【发布时间】:2017-08-07 14:14:11
【问题描述】:
我还没有找到正确的答案。这是我第一个使用 Android Studio 的项目,我几乎失去了耐心 :)。 Theme.AppCompat.Light.DarkActionBar 标记为红色。
这是我的styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
这是我的 build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "helloworld.spsa3.helloworldproject"
minSdkVersion 10
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
}
最后这是我的第二个问题,我确信它们是相关的。 “R”也无法解析。 “R”也标记为红色。
这是我的 MainActivityFragment() 类:
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class MainActivityFragment extends Fragment{
public MainActivityFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_main, container, false);
}
}
有什么想法吗?
【问题讨论】:
-
这意味着您的布局文件或可绘制对象中存在一些编译问题。基本上 res 文件夹中的任何内容都可能导致 R 无法编译
-
尝试构建 -> 清理项目
-
@kapsym 所以你知道如何解决这个问题。你有没有遇到过同样的问题?
-
@SaurabhThorat 这不起作用
-
检查您的资源文件名中是否存在无效字符。如果 any 有 single 无效字符,您将无法编译 R.java。
标签: android android-studio android-gradle-plugin build.gradle