You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

未找到AppCompatActivity,AndroidStudio运行App崩溃求助(Udacity学员)

Fixing "Didn't find AppCompatActivity on path" & App Crashes on OnePlus 5

Hey there! Sorry to hear you're hitting these frustrating crashes while trying to get your first app running on your OnePlus 5—let's break down what's going on and fix it step by step. The key red flag here is "Didn't find AppCompatActivity on path"—this is almost always a problem with your project's dependencies not being set up correctly.

Step 1: Check your Module-level build.gradle file

The AppCompatActivity class comes from the AndroidX AppCompat library, so we need to make sure it's properly included in your project:

  • Open the build.gradle file located inside the app folder of your project (not the top-level project build.gradle—this is a common mix-up!).
  • Look for the dependencies block, and confirm it includes this line (you can use the latest version or the one recommended in your Udacity course):
    implementation 'androidx.appcompat:appcompat:1.6.1'
    
  • If the line is missing, add it; if it's already there, double-check the version number isn't outdated.

Step 2: Verify your Activity inheritance

Open your main Activity class (probably MainActivity.java or MainActivity.kt) and make sure it extends AppCompatActivity, not the basic Activity class:

  • For Java:
    public class MainActivity extends AppCompatActivity {
        // ... your existing code here
    }
    
  • For Kotlin:
    class MainActivity : AppCompatActivity() {
        // ... your existing code here
    }
    

Step 3: Sync, Clean, and Rebuild your project

  • After updating the build.gradle file, click the Sync Now button that pops up in the top-right corner of Android Studio to download the missing dependency.
  • Once sync finishes, go to the top menu: Build > Clean Project to clear any cached build files that might be causing conflicts.
  • Then run Build > Rebuild Project to create a fresh, clean build of your app.

Step 4: Double-check your OnePlus 5 debugging settings

While the core issue is the dependency, let's rule out any device-side hiccups:

  • Ensure USB Debugging is enabled in your phone's Developer Options (if you don't see Developer Options, go to Settings > About Phone and tap the Build Number 7 times to unlock it).
  • When you connect your phone to your computer, select File Transfer/Android Auto mode, and tap "Allow" on the USB debugging prompt that pops up on your phone screen.

The different crash messages ("MyApp已停止" and "Happy Birthday keeps stopping") are likely just leftover from previous project builds or name changes—once we fix the AppCompatActivity dependency issue, these crashes should disappear entirely.

内容的提问来源于stack exchange,提问作者Oatnuj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:28:21