compileSdkVersion不受支持

时间:2018-05-23 20:40:52

标签: android-studio sdk android-gradle build.gradle

我有Android应用程序和编码仅支持API 26,而我有Note4支持Api23。

我尝试覆盖Manifest文件调整,但没有运气。请指教。

请注意,我可以将minSdk降级为API 23,以便注释4可以工作,但问题是时间和日期计算的编码仅适用于API 26.

我的错误。 enter image description here

现有代码:CourseSearchActivity.java

package com.bar.example.myapplication;


import android.app.AlertDialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Spinner;
import android.widget.Toast;
import android.util.Log;
import java.util.Date;
import java.time.format.DateTimeParseException;

import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.AdapterView.OnItemSelectedListener;
import android.text.format.DateFormat;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.time.temporal.ChronoUnit;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import static java.lang.Math.abs;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import android.Manifest.permission;

import com.google.zxing.Result;

import me.dm7.barcodescanner.zxing.ZXingScannerView;

import static android.Manifest.permission.CAMERA;

public class CourseSearchActivity extends AppCompatActivity {

  private DBHelper db;
  private List < Course > allCoursesList;
  private List < Offering > allOfferingsList;
  private List < Offering > filteredOfferingsList;
  public TextView txtResult, tv, textDivNumber, textAVG, txtZaMisiac;
  public static TextView tvresult;
  public Button reset, button, button1, button2, button9, editTextDate3, editTextDate5, btnok;
  public EditText barcodeResult;
  public static EditText courseTitleEditText;
  public Spinner ok, ok1;
  private ListView offeringsListView;

  // private selectedInstructorName selectedInstructorName;
  private InstructorSpinnerAdapter instructorSpinnerAdapter;
  Cursor spinner1csr, spinner2csr, spinner3csr, spinner4csr, search;
  SimpleCursorAdapter sca, sca2, sca3, sca4, sca6;
  long spinner1_selected = 0;
  private static DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("d.M.uuuu");


  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_course_search);

    deleteDatabase(DBHelper.DATABASE_NAME);
    db = new DBHelper(this);
    db.importCoursesFromCSV("courses.csv");

    db.importOfferingsFromCSV("offerings.csv");
    //  Button reset = (Button) findViewById(R.id.resetButton);
    allOfferingsList = db.getAllOfferings();
    filteredOfferingsList = new ArrayList < > (allOfferingsList);
    btnok = (Button) findViewById(R.id.btnok);
    allCoursesList = db.getAllCourses();
    tvresult = (TextView) findViewById(R.id.textView12);
    courseTitleEditText = (EditText) findViewById(R.id.courseTitleEditText);
    courseTitleEditText.addTextChangedListener(courseTitleTextWatcher);
    // editTextDate5 = (EditText) findViewById(R.id.editText5);
    //  editTextDate3 = (Button) findViewById(R.id.editText3);
    editTextDate5 = (Button) findViewById(R.id.editText5);
    button2 = (Button) findViewById(R.id.btnDate2);
    txtResult = (TextView) findViewById(R.id.editText2);
    editTextDate5.setText(DateFormat.format("dd.MM.yyyy", new java.util.Date()).toString());
    ok = (Spinner) findViewById(R.id.spinner1);
    ok1 = (Spinner) findViewById(R.id.spinner2);

    // offeringListAdapter = new OfferingListAdapter(this, R.layout.offering_list_item, filteredOfferingsList);
    // ok.setAdapter(offeringListAdapter);
    instructorSpinnerAdapter = new InstructorSpinnerAdapter(this, R.layout.offering_list_item, filteredOfferingsList);
    //ArrayAdapter<String> instructorSpinnerAdapter = new ArrayAdapter<String>
    //(this, android.R.layout.simple_spinner_item, getAllCourse());
    ok.setAdapter(new ArrayAdapter < > (this, android.R.layout.simple_spinner_item, getAllCourse()));
    ok1.setAdapter(new ArrayAdapter < > (this, android.R.layout.simple_spinner_item, getAllCourseNumber()));


    //   ok.setAdapter(instructorSpinnerAdapter);
    //  ok1.setAdapter(instructorSpinnerAdapter);
    ok.setOnItemSelectedListener(instructorSpinnerListener);

    ok1.setOnItemSelectedListener(instructorSpinnerListener);

    btnok.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        Intent intent = new Intent(CourseSearchActivity.this, ScanActivity.class);
        startActivity(intent);
      }
    });

  }


  private String[] getAllCourse1() {
    String[] instructorNames = new String[allCoursesList.size() + 1];
    instructorNames[0] = "[Select Course]";

    for (int i = 1; i < instructorNames.length; i++) {
      instructorNames[i] = allCoursesList.get(i - 1).getTitle();
    }
    return instructorNames;
  }

  private ArrayList < String > getAllCourseNumber() {
    ArrayList < String > instructorNames = new ArrayList < > ();
    instructorNames.add("[Select Material Desc]");
    for (int i = 0; i < allCoursesList.size(); i++) {
      instructorNames.add(allCoursesList.get(i).getNumber());
    }
    return instructorNames;
  }

  private ArrayList < String > getAllCourse() {
    ArrayList < String > instructorNames = new ArrayList < > ();
    instructorNames.add("[Select Material]");

    for (int i = 0; i < allCoursesList.size(); i++) {

      instructorNames.add(allCoursesList.get(i).getTitle());

    }
    return instructorNames;
  }

  public TextWatcher courseTitleTextWatcher = new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

    }

    @Override
    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
      String input = charSequence.toString().toLowerCase();
      ArrayAdapter adapter = (ArrayAdapter) ok.getAdapter();
      ArrayAdapter adapter1 = (ArrayAdapter) ok1.getAdapter();
      adapter.clear();
      adapter1.clear();
      if (input.equals("")) {
        adapter.addAll(getAllCourse());
        adapter1.addAll(getAllCourseNumber());
      } else {
        Course course;

        for (int j = 0; j < allCoursesList.size(); j++) {
          // If the course title starts with the user input,
          // add it to the listAdapter
          course = allCoursesList.get(j);
          if (course.getAlpha().toLowerCase().startsWith(input) || course.getNumber().toLowerCase().startsWith(input)) {
            adapter.add(course.getTitle());
            adapter1.add(course.getNumber());
          }
        }
      }
      adapter.notifyDataSetChanged();
      adapter1.notifyDataSetChanged();
      if (adapter.getCount() != 0) ok.setSelection(0);
      if (adapter1.getCount() != 0) ok1.setSelection(0);
    }


    @Override
    public void afterTextChanged(Editable editable) {


    }
  };
  public AdapterView.OnItemSelectedListener instructorSpinnerListener = new AdapterView.OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView << ? > adapterView, View view, int i, long l) {
      // Sync the selection of the two spinners.
      if (adapterView.getId() == R.id.spinner1) {
        ok1.setOnItemSelectedListener(null);
        ok1.setSelection(i);
        ok1.setOnItemSelectedListener(this);
      } else {
        ok.setOnItemSelectedListener(null);
        ok.setSelection(i);
        ok.setOnItemSelectedListener(this);
      }
      // No matter which spinner is selected, get item from the ok [Title] spinner.
      String selectedInstructorName = ok.getItemAtPosition(i).toString();
      if (selectedInstructorName.equals("[Select Instructor]")) {
        instructorSpinnerAdapter.clear();
        for (Offering offering: allOfferingsList)
          instructorSpinnerAdapter.add(offering);
      } else {
        instructorSpinnerAdapter.clear();
      }
    }
    @Override
    public void onNothingSelected(AdapterView << ? > adapterView) {
      adapterView.setSelection(0);
      // Toast.makeText(getApplicationContext(), "Why?", Toast.LENGTH_SHORT).show();
    }
  };

  public void diff(View view) {
    SimpleDateFormat myFormat = new SimpleDateFormat("dd.MM.yyyy");
    CharSequence inputString1 = editTextDate5.getText();
    try {
      LocalDate date1 = LocalDate.parse(inputString1, dateFormatter);
      CharSequence inputString2 = button2.getText();
      try {
        LocalDate date2 = LocalDate.parse(inputString2, dateFormatter);
        long diffDate = ChronoUnit.DAYS.between(date1, date2);
        txtResult.setText(String.valueOf(diffDate));
      } catch (DateTimeParseException dtpe) {
        Toast.makeText(this, "Date2 is not a valid date: " + inputString2, Toast.LENGTH_SHORT).show();
      }
    } catch (DateTimeParseException dtpe) {
      Toast.makeText(this, "Date1 is not a valid date: " + inputString1, Toast.LENGTH_SHORT).show();
    }
  }

  public void setDate1(View view) {
    DialogFragment newFragment = new DatePickerFragment();
    newFragment.show(getFragmentManager(), "Date Picker");
  }
  public void setDate2(View view) {
    DialogFragment newFragment = new DatePickerFragment2();
    newFragment.show(getFragmentManager(), "Date Picker");
  }


}

的Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.bar.example.myapplication">

  <uses-permission android:name="android.permission.CAMERA" />

  <uses-feature android:name="android.hardware.camera" />
  <uses-feature android:name="android.hardware.camera.autofocus" />
  <uses-sdk android:minSdkVersion='23' android:compileSdkVersion='23' />


  <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">
    <activity android:name=".CourseSearchActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <activity android:name=".ScanActivity"></activity>

  </application>

</manifest>

的build.gradle(Module.app)

apply plugin: 'com.android.application'

android {
  compileSdkVersion 26
  buildToolsVersion "25.0.3"
  defaultConfig {
    applicationId "com.bar.example.myapplication"
    // minSdkVersion 26
    minSdkVersion 26
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"


  }
  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
  productFlavors {}
}

dependencies {
  compile fileTree(include: ['*.jar'], dir: 'libs')
  androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support',
    module: 'support-annotations'
  })
  //compile 'me.dm7.barcodescanner:zxing:1.9'
  // compile 'com.android.support:appcompat-v7:25+'
  compile 'com.android.support:appcompat-v7:23.4.0'
  compile 'com.edwardvanraak:MaterialBarcodeScanner:0.0.6-ALPHA'
  implementation 'com.android.support.constraint:constraint-layout:1.1.0'
  testImplementation 'junit:junit:4.12'
  implementation 'com.google.zxing:core:3.2.0'
  compile 'me.dm7.barcodescanner:zxing:1.9'
}

1 个答案:

答案 0 :(得分:0)

您的minSdkVersion为26.这意味着API 26下的设备无法运行该应用。

您的设备正在运行API 23,因此运行太旧的API来运行它。要么降低你的minSDK版本,要么使用更新版本的Android使用不同的设备。你必须在Gradle文件中覆盖它;它写入清单并覆盖你在那里的任何东西。

如果您使用需要API 26的API,那么无法降低它,那么除非您添加对API 25及更低版本的支持,否则您根本无法使用API​​ 23设备