Android Manifest报错:uses-sdk元素必须是manifest根元素的直接子元素
Hey there! I’ve dealt with this exact problem before when setting up SDK versions for libraries like Helpshift—super common issue, and easy to fix once you know what’s going on.
What’s causing the error?
The Android manifest has strict rules about where certain tags can live. The <uses-sdk> tag cannot be nested inside any other elements (like <application>, <activity>, or <permission>). It has to be a direct child of the root <manifest> element. Chances are you accidentally placed it somewhere else in your manifest file.
How to fix it
- Open your
AndroidManifest.xmlfile in Android Studio. - Locate your
<uses-sdk>tag—right now it’s probably inside another element (most likely<application>). - Cut that entire
<uses-sdk>block. - Paste it right after the opening
<manifest>tag (before any other elements like<application>or<uses-permission>).
Here’s what your corrected manifest should look like (with placeholder package name):
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.your.app.package"> <!-- Correct placement: Direct child of <manifest> --> <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="26" android:compileSdkVersion="26" android:buildToolsVersion="26" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme"> <!-- Your activities, services, receivers go here --> </application> </manifest>
Quick check
After moving the tag, sync your project with Gradle (click the "Sync Project with Gradle Files" button in Android Studio). The error should disappear immediately if the placement is correct. Also, double-check that Helpshift’s SDK requirements align with your minSdkVersion—Helpshift typically supports minSdk 14+, which matches your setup, so that should be good to go.
内容的提问来源于stack exchange,提问作者Sam Wilson

