导入网上下载的Android Studio项目出现的问题及解决方案总结:

导入网上下载的Android Studio项目出现的问题及解决方案总结:

基本配置信息更改:

首先,要让项目在自己的Android Studio上运行,需要在下载的项目包中更改几个基本的配置信息:

1.在下载的项目包中找到最外层的build.gradle文件用文本编辑器打开,升级gradle依赖,更新gradle的版本号到3.2.1

		// 版本号根据自己的工具来
		classpath 'com.android.tools.build:gradle:3.2.1'

2.在app文件夹下找到build.gradle文件打开,将compileSdkVersion以及targetSdkVersion改为新版28

apply plugin: 'com.android.application'
		android {
		    compileSdkVersion 28
		    defaultConfig {
		        applicationId "com.hl.www.helloandroid"
		        minSdkVersion 23
		        targetSdkVersion 28
		        versionCode 1
		        versionName "1.0"
		        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
		  ...

3.进入gradle文件夹->wrapper文件夹,打开gradle-wrapper.properties,将其中一项改为新版包gradle-4.6-all.zip:

		distributionBase=GRADLE_USER_HOME
		distributionPath=wrapper/dists
		distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
		zipStoreBase=GRADLE_USER_HOME
		zipStorePath=wrapper/dists

接下来一般就可以进行编译。

编译报错问题总结:

1:Configuration ‘compile’ is obsolete and has been replaced with ‘implementation’ and ‘api’.It will be removed at the end of 2018. For more information see:

dependencies { 
	compile fileTree(dir: 'libs', include: ['*.jar']) 
	androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
		exclude group: 'com.android.support', module: 'support-annotations' 
	}) 
	compile 'com.android.support:appcompat-v7:25.3.1' 
	compile 'com.android.support.constraint:constraint-layout:1.0.2' 
	compile 'com.android.support:support-core-ui:25.3.1' 
	compile 'com.android.support:design:25.3.1' 
	testCompile 'junit:junit:4.12' 
}

问题分析:配置中的一些api已经过时,需替换;
解决方案:将配置文件中出现的:
compile 改成implementation
androidTestCompile改成androidTestImplementation
testCompile 改成testImplementation

dependencies { 
	implementation fileTree(dir: 'libs', include: ['*.jar']) 
	androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { 
		exclude group: 'com.android.support', module: 'support-annotations' 
	}) 
	implementation 'com.android.support:appcompat-v7:25.3.1' 
	implementation 'com.android.support.constraint:constraint-layout:1.0.2' 
	implementation 'com.android.support:support-core-ui:25.3.1' 
	implementation 'com.android.support:design:25.3.1' 
	testImplementation 'junit:junit:4.12' 
}

2:Error:android-apt plugin is incompatible with the Android Gradle plugin. Please use ‘annotationProcessor’ configuration instead;

问题分析:新版Android Studio所搭配的com.android.tools.build:gradle:3.0.0及更高版本不支持1.8版本的apt;
解决方案:先把project的build.gradle中的
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8’语句删掉,
然后把module的build.gradle中的
apply plugin: 'com.neenbedankt.android-apt’语句也删掉,
再把之前dependencies中
apt 'com.jakewharton:butterknife-compiler:8.8.1’中的apt换成annotationProcessor

3:Android studio 3.0 com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

问题分析:配置问题;
参考解决方案:将compile(name: ‘guavalib’, ext: ‘jar’)修改为compile files(‘libs/guavalib.jar’)。

4:Annotation processors must be explicitly declared now. The following dependenci

问题分析:注解报错;
解决方案:在app的build.gradle中

android { 
		... 
		defaultConfig { 
			... 
			//添加如下配置 
			javaCompileOptions 
			{ annotationProcessorOptions {includeCompileClasspath = true } 
		} 
	}

5:Android-ABIFilter-Device supports x86,but APK only supports armeabi-v7a,armeabi,x86_64

问题分析:apk不支持设备的机型;
参考解决方案:删除配置

defaultConfig {
        ndk {
            abiFilters "armeabi", "armeabi-v7a", "x86_64"
        }
    }

中的 ndk {abiFilters “armeabi”, “armeabi-v7a”, “x86_64”} 语句。

6:Error:All flavors must now belong to a named flavor dimension. Learn more at

解决方案:在app的build.gradle中

defaultConfig {
	 	targetSdkVersion:***
		minSdkVersion :***
		versionCode:***
	 	versionName :***

		//在这里版本名后面添加一句话,意思就是flavor dimension 它的维度就是该版本号
		flavorDimensions "versionCode"
	}

7:The specified Android SDK Build Tools version (25.0.0) is ignored, as it is below the minimum supported version (27.0.3) for Android Gradle Plugin 3.1.2.

问题分析:Android Studio3.0之后不需要再指定buildToolsVersion;
解决方案:将出错配置中buildToolsVersion语句删除。

8:All flavors must now belong to a named flavor dimension.

参考解决方案:在defaultconfig里面添加语句:
flavorDimensions ‘default’

9:DSL element ‘DexOptions.incremental’ is obsolete and will be removed at the end of 2018.

问题分析:incremental这个将在2018年后被弃用;
解决方案:删除incremental语句。

10:Failed to resolve: runtime

解决方案:在项目根目录下的build.gradle的allprojects新添加google()

allprojects {
    		repositories {
      		  google()//新添加
        	  jcenter()
    }
}

11:com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

dependencies { 
		api fileTree(dir: 'libs', include: ['*.jar']) testApi 'junit:junit:4.12' 
		androidTestApi 'com.android.support.test:runner:1.0.1' 
		androidTestApi 'com.android.support.test.espresso:espresso-core:3.0.1' 
		api 'com.android.support.constraint:constraint-layout:1.1.0' 
		api 'com.android.support:appcompat-v7:26.1.0' 
		api 'com.android.support:design:26.1.0' 
		api 'com.github.bumptech.glide:glide:4.7.1' 
		annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1' 
}

参考解决方案:将编译的版本修改为最新的,确认compileSdkVersion以及targetSdkVersion已被改为新版28;接着改:

dependencies { 
		api fileTree(dir: 'libs', include: ['*.jar']) testApi 'junit:junit:4.12' 
		androidTestApi 'com.android.support.test:runner:1.0.1' 
		androidTestApi 'com.android.support.test.espresso:espresso-core:3.0.1' 
		api 'com.android.support.constraint:constraint-layout:1.1.0' 
		api 'com.android.support:appcompat-v7:28.+'(此处) 
		api 'com.android.support:design:28.+' (此处)
		api 'com.github.bumptech.glide:glide:4.7.1' 
		annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1' 
}

编译正常,运行报错总结:

1:Program type already present: android.support.v4.view.ViewPager$SavedState$1;

dependencies {
	    implementation fileTree(include: ['*.jar'], dir: 'libs')
	    implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
	    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
	    testImplementation 'junit:junit:4.12'
	    androidTestImplementation 'com.android.support.test:runner:1.0.2'
	    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
	    implementation 'de.mrmaffen:vlc-android-sdk:3.0.0'
	}

问题分析:com.android.support 包引用重复;
参考解决方案:在依赖中排除com.android.support:

dependencies {
	    implementation fileTree(include: ['*.jar'], dir: 'libs')

	    implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
	    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
	    testImplementation 'junit:junit:4.12'
	    androidTestImplementation 'com.android.support.test:runner:1.0.2'
	    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
	    implementation ('de.mrmaffen:vlc-android-sdk:3.0.0') {exclude group: 'com.android.support'}(添加语句)
	}

2:Program type already present: android.support.v4.app.BackStackRecord$Op
3:Program type already present: android.support.v4.app.ActionBarDrawerToggle$Delegate

参考解决方案:在配置文件中的 implementation 'com.android.support:appcompat-v7:27.1.1’后加上implementation ‘com.android.support:support-v4:27.1.1’

dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') testImplementation 'junit:junit:4.12'
	    implementation 'com.google.code.gson:gson:2.3.1'
	    implementation project(':library-pulltorefresh') implementation 'com.mcxiaoke.volley:library:1.0.16'
	    implementation project(':library-sidedrawer') implementation project(':library-circleimageview') implementation 'com.android.support:appcompat-v7:27.1.1'
	    implementation 'com.android.support:support-v4:27.1.1'
	    implementation project(':library-slidingmenu') implementation 'com.baoyz.swipemenulistview:library:1.3.0'
	    implementation 'org.greenrobot:eventbus:3.0.0'
	}

4:Android studio 3.0 com.android.builder.dexing.DexArchiveMergerException: Unable to mer
5:Error:\warning: Ignoring InnerClasses attribute for an anonymous inner class

参考解决方案:首先修改Gradle配置文件,

defaultConfig {
	multiDexEnabled true
}

同样修改Gradle配置文件,

dependencies { 
	implementation 'com.android.support:multidex:1.0.1' 
} 

然后让应用支持多DEX文件,在AndroidManifest.xml的application中声明android.support.multidex.MultiDexApplication
即:

android:name="android.support.multidex.MultiDexApplication"

结语

小白总结,仅供参考;
如有错误,欢迎指正。








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值