gpt4 book ai didi

java - 包 android.support.v4.app 不存在

转载 作者:行者123 更新时间:2023-11-29 23:53:35 27 4
gpt4 key购买 nike

在我的 Qt Android(5.6+,最新的 SDK 和 NDK 10d)应用程序中,由于 targetApi 26,我需要在运行时请求权限。From Google docs我发现我必须做这样的事情:

import android.Manifest.permission;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;

public class MyActivity extends QtActivity implements ActivityCompat.OnRequestPermissionsResultCallback
{
private static final String[] LOCATION_PERMS = {
permission.ACCESS_FINE_LOCATION
};
private static final int LOCATION_REQUEST = 1337;

private boolean hasPermission(String perm)
{
return (PackageManager.PERMISSION_GRANTED == checkSelfPermission(perm));
}

public boolean canAccessLocation()
{
return hasPermission(permission.ACCESS_FINE_LOCATION);
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
{
//Figure out what was given to us
switch(requestCode)
{
case LOCATION_REQUEST:
if (canAccessLocation())
Log.i(TAG, "Access to location is granted");
else {
Log.e(TAG, "Access to location is denied");
finish();
}
break;
}
}

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

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//Ensure we can run the app
if (!canAccessLocation())
requestPermissions( LOCATION_PERMS, LOCATION_REQUEST );
}
}
}

我还安装了 Android 支持存储库: enter image description here

这是我的build.gradle:

buildscript {
repositories {
jcenter()
google()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
}
}

allprojects {
repositories {
jcenter()
google()
}
}

apply plugin: 'com.android.application'

dependencies {
compile "com.android.support:support-v4:27.0.2"
compile "com.android.support:support-v13:27.0.2"
compile fileTree(dir: 'libs', include: ['*.jar'])
}

但我得到错误:package android.support.v4.app does not exist。我还试图在我的工作站上找到 android-support-v4.jar 但没有成功。添加

compile 'com.android.support:support-v4:+'

from here没有任何区别。

一件重要的事情:我的项目是在 CMake 的帮助下从命令行构建的,我不能使用任何 IDE,如 Android Studio 或 Eclipse。我错过了什么?

谢谢!

更新:完整错误列表: enter image description here

最佳答案

我不知道你是否还有这个问题,但万一有人想知道...

我将编译 sdk 版本更改为:27:Android 8.1 (Oreo) 26:Android 8.0 (Oreo)在 build.grade

dependencies {
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support:design:27.0.0'
implementation 'com.android.support:support-v4:27.1.1'
}

显然 android.support:support 中的 27.1.1 起到了作用(27.0.0 不起作用)。我希望这有助于 (:

关于java - 包 android.support.v4.app 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50626870/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com