导入API18的Eclipse ADT项目至AndroidStudio后Gradle构建Material样式报错求助
Hey there, let's tackle this error you're seeing. Those missing TextAppearance.Material resources are a common issue when importing old Eclipse projects (targeting API 18) into Android Studio, and here's why and how to fix it:
What's Causing This?
Material Design-related styles like TextAppearance.Material were first introduced in Android 5.0 (API Level 21). Your project is set to target API 18, but the auto-generated Gradle config from the import might be pulling in newer support libraries or using a higher compile SDK that references these incompatible resources.
Step 1: Fix Your Module's build.gradle Config
Open your app-level build.gradle file (under app/) and adjust these key settings:
Set a Compatible Compile SDK Version
You can keep supporting API 18 as your minimum, but setcompileSdkVersionto 21 or higher (I recommend 28 for better compatibility with older support libraries):android { compileSdkVersion 28 defaultConfig { applicationId "your.package.name" minSdkVersion 18 targetSdkVersion 18 // You can upgrade this to 28 if you want, but 18 works too versionCode 1 versionName "1.0" } }Update Support Library Versions
From your import summary,android-support-v4.jarwas replaced withcom.android.support:support-v4:18.0.0—this version is way too old. Match it to yourcompileSdkVersion:dependencies { // For SDK 28, use this: implementation 'com.android.support:support-v4:28.0.0' // If you're using appcompat, add this too (same version): // implementation 'com.android.support:appcompat-v7:28.0.0' }Pro tip: If you use
appcompat-v7, its version must match yourcompileSdkVersionto avoid resource conflicts.Pin Google Play Services Version
The import usedcom.google.android.gms:play-services:+, which pulls the latest version (incompatible with API 18). Use a stable version that works with your compile SDK:// For SDK 28, this version works well: implementation 'com.google.android.gms:play-services:17.0.0' // Even better: Only import the modules you need (e.g., maps, location) to reduce app size // implementation 'com.google.android.gms:play-services-maps:17.0.0'
Step 2: Check Your App's Theme
Open res/values/styles.xml and make sure your theme uses a backward-compatible parent, not a Material-only one:
<!-- Avoid Theme.Material (API 21+ only) --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Your custom theme attributes go here --> </style>
If your original Eclipse project used Theme.Holo styles, you can keep using those too—but AppCompat themes offer better cross-version support.
Step 3: Clean & Rebuild
After making these changes:
- Go to
Build > Clean Project - Then
Build > Rebuild Project - If you still have issues, try
File > Invalidate Caches... > Invalidate and Restartto clear Android Studio's cache.
If It Still Doesn't Work, Share These Details
If the above steps don't fix the error, I'll need a bit more info to help:
- Full content of your app-level
build.gradlefile - Contents of
res/values/styles.xmlandres/values-v21/styles.xml(if it exists) - Any other library dependencies your project uses that might reference Material styles
内容的提问来源于stack exchange,提问作者me.at.coding

