API 级别 28 的编译错误 [英] Compiling errors at API level 28

查看:20
本文介绍了API 级别 28 的编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 API 级别 28 (compileSdkVersion 28) 的源代码编译 .apk.该应用程序编译正常,但安装后崩溃.我的应用程序在各个页面的 UI 中都有 Admob 广告.

I'm trying to compile an .apk from source code at API level 28 (compileSdkVersion 28). The app compiles fine but after installation it crashes. My app has Admob Ads in the UI itself on various pages.

这是我的项目级 build.gradle -

Here's my project-level build.gradle -

    buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
        classpath 'com.google.gms:google-services:4.2.0'
    }
}

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

这是我的应用级 build.gradle -

Here's my app-level build.gradle -

apply plugin: 'com.android.application'

android {
    useLibrary 'org.apache.http.legacy'
    compileSdkVersion 28

    defaultConfig {
        applicationId "****APP_ID****"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.google.android.gms:play-services-ads:17.2.1'
    implementation 'com.android.support:customtabs:27.0.2'
    implementation 'com.google.android.gms:play-services-maps:+'
    implementation 'com.google.code.gson:gson:2.8.0'
    implementation 'com.github.bumptech.glide:glide:3.7.0'
    implementation 'com.squareup.okhttp3:okhttp:3.9.1'
}
apply plugin: 'com.google.gms.google-services'

这是我的 AndroidManifest.xml 中的广告代码 -

Here's the Ad code from my AndroidManifest.xml -

 <application>
    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="*****ADMOB-ID*****"/>
</application>

这是我的 MainActivity.java 中的广告代码

Here's the Ad code from my MainActivity.java

import com.google.android.gms.ads.MobileAds;
public class MainActivity extends Activity {


      private LinearLayout linear1;
      private AdView adview1;
      @Override
      protected void onCreate(Bundle _savedInstanceState) {
         super.onCreate(_savedInstanceState);
         setContentView(R.layout.main);
         initialize(_savedInstanceState);
         initializeLogic();
         MobileAds.initialize(this, "*****ADMOB-ID*****");
     }

我对 Android 编码比较陌生.可能是什么问题?

I'm relatively new to Android coding. What might be the problem?

推荐答案

您必须从您的应用程序中禁用 org.apache.http.legacy,因此在清单中添加以下行

You have to disable org.apache.http.legacy from your application so add below lines in manifest

 <uses-library
  android:name="org.apache.http.legacy"
  android:required="false" />

从 gradle 中删除 useLibrary 'org.apache.http.legacy'

remove useLibrary 'org.apache.http.legacy' from gradle

如果您在应用程序中使用任何 http 网址,参考这个

If you are using any http url in your application, refer this

这篇关于API 级别 28 的编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆