简体   繁体   中英

How do I get example code from Android to run on an older phone?

I am trying to get the sample camera app, called Camera2Basic, that was released with API 21 to compile on my 4.0.3 (API 15) test phone. It's located at http://developer.android.com/samples/Camera2Basic/project.html . I imported the project and have changed the code in build.gradle to

defaultConfig {
    minSdkVersion 15
    targetSdkVersion 21
}

I'm getting a lot of errors, the first being:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.camera2basic/com.example.android.camera2basic.CameraActivity}: android.view.InflateException: Binary XML file line #30: Error inflating class com.android.internal.widget.ActionBarView

I have tried researching the errors independently but I feel I'm missing something important. Any recommendations?

Edit: I also have added the dependency for the support library to build.gradle:

dependencies {
    compile "com.android.support:support-v4:21.0.+"
}

There could be many errors when executing newest API on older Android version. There could be used functions from API 21 that are not present in API 15 device. Have you changed your project compile api(not only in code but whole project build)? In eclipse its located in project properties -> Android. If not thats why you are able to compile this code without errors. After change you will see those functions which are not present in API 15

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM