将应用程序从 Eclipse 移植到 Android Studio 时出错

Posted

技术标签:

【中文标题】将应用程序从 Eclipse 移植到 Android Studio 时出错【英文标题】:Error while porting app from Eclipse to Android Studio 【发布时间】:2014-11-06 23:14:35 【问题描述】:

我正在将一个项目从 Eclipse 移植到最新的 android Studio。通过复制 AS 使用的目录中的所有文件一切正常,但实际上我使用的所有库和从我自己的项目中导入的文件都出现了许多错误:可能是什么问题?这是错误列表:(当然,未找到的符号很好,可以在项目中使用)。

/Users/fbartolom/Documents/Android/TaxiProfessional/app/src/main/java/info.inarrivo.taxiprofessional/LoginActivity.java
Error:(10, 30) error: package com.google.android.gcm does not exist
Error:(29, 73) error: interface expected here
/Users/fbartolom/Documents/Android/TaxiProfessional/app/src/main/java/info.inarrivo.taxiprofessional/NearStatus.java
Error:(8, 33) error: cannot find symbol class BookingStatus
Error:(8, 58) error: cannot find symbol class UrlConnectionDelegate
Error:(10, 17) error: cannot find symbol class BookingStatus
Error:(11, 2) error: cannot find symbol class Dashboard
Error:(13, 16) error: cannot find symbol class BookingStatus
Error:(23, 12) error: cannot find symbol class BookingStatus
Error:(44, 12) error: cannot find symbol class Status
Error:(48, 2) error: cannot find symbol class BookingStatus
/Users/fbartolom/Documents/Android/TaxiProfessional/app/src/main/java/info.inarrivo.taxiprofessional/Reservation.java
Error:(38, 37) error: cannot find symbol class UrlConnectionDelegate
Error:(70, 10) error: cannot find symbol class Status
Error:(87, 9) error: cannot find symbol class Status
Error:(91, 31) error: cannot find symbol class Status
Error:(94, 2) error: cannot find symbol class Line
Error:(95, 2) error: cannot find symbol class Line
Error:(97, 13) error: cannot find symbol class SimpleGeofence
Error:(101, 13) error: cannot find symbol class SimpleGeofenceStore
Error:(343, 2) error: cannot find symbol class Status
Error:(366, 18) error: cannot find symbol class Status
/Users/fbartolom/Documents/Android/TaxiProfessional/app/src/main/java/info.inarrivo.taxiprofessional/ReservationManager.java
Error:(6, 9) error: cannot find symbol class Reservation
/Users/fbartolom/Documents/Android/TaxiProfessional/app/src/main/java/info.inarrivo.taxiprofessional/RunningStatus.java
Error:(18, 3) error: interface expected here
/Users/fbartolom/Documents/Android/TaxiProfessional/app/src/main/java/info.inarrivo.taxiprofessional/ServerUtilities.java
Error:(14, 43) error: cannot find symbol class CommonUtilities
Error:(14, 1) error: static import only from classes and interfaces
Error:(15, 43) error: cannot find symbol class CommonUtilities
Error:(15, 1) error: static import only from classes and interfaces
Error:(16, 43) error: cannot find symbol class CommonUtilities
Error:(16, 1) error: static import only from classes and interfaces
/Users/fbartolom/Documents/Android/TaxiProfessional/app/src/main/java/info.inarrivo.taxiprofessional/Taximeter.java
Error:(27, 62) error: interface expected here
/Users/fbartolom/Documents/Android/TaxiProfessional/app/src/main/java/info.inarrivo.taxiprofessional/AccountInformation.java
Error:(12, 58) error: interface expected here
Error:(182, 24) error: incompatible types: AccountInformation cannot be converted to UrlConnectionDelegate
/Users/fbartolom/Documents/Android/TaxiProfessional/app/src/main/java/info.inarrivo.taxiprofessional/BackgroundLocationService.java
Error:(42, 67) error: interface expected here
Error:(118, 22) error: incompatible types: BackgroundLocationService cannot be converted to UrlConnectionDelegate
/Users/fbartolom/Documents/Android/TaxiProfessional/app/src/main/java/info.inarrivo.taxiprofessional/DashboardActivity.java
Error:(5, 46) error: package com.example.taxiprofessional.Taximeter does not exist
Error:(45, 34) error: interface expected here
Error:(427, 3) error: cannot find symbol class Reservation
Error:(440, 4) error: cannot find symbol class Reservation
Error:(440, 34) error: cannot find symbol class Reservation
Error:(455, 22) error: incompatible types: DashboardActivity cannot be converted to UrlConnectionDelegate
Error:(462, 3) error: cannot find symbol class Reservation
Error:(462, 33) error: cannot find symbol class Reservation
Error:(487, 21) error: incompatible types: DashboardActivity cannot be converted to UrlConnectionDelegate
Error:(522, 3) error: cannot find symbol class Reservation
Error:(622, 2) error: method does not override or implement a method from a supertype
Error:(628, 2) error: method does not override or implement a method from a supertype
Error:(683, 66) error: cannot find symbol variable NearStatus
/Users/fbartolom/Documents/Android/TaxiProfessional/app/src/main/java/info.inarrivo.taxiprofessional/PollService.java
Error:(29, 53) error: interface expected here
Error:(60, 48) error: cannot find symbol class Dashboard
Error:(106, 27) error: incompatible types: PollService cannot be converted to UrlConnectionDelegate
Error:(101, 15) error: package Dashboard does not exist
Error:(123, 30) error: cannot find symbol variable Dashboard
Error:(130, 51) error: cannot find symbol class Dashboard
Error:(140, 21) error: package NotificationCompat does not exist
Error:(140, 62) error: package NotificationCompat does not exist
Error:(189, 64) error: cannot find symbol class Reservation
Error:(246, 69) error: cannot find symbol variable NearStatus
Error:(217, 14) error: package Dashboard does not exist
/Users/fbartolom/Documents/Android/TaxiProfessional/app/src/main/java/info.inarrivo.taxiprofessional/Line.java
Error:(117, 50) error: cannot find symbol variable Dashboard
Error:(143, 29) error: package Dashboard.dashboard does not exist
Error:(146, 28) error: package Dashboard.dashboard does not exist
Error:(161, 47) error: package Dashboard.dashboard does not exist
Error:(220, 34) error: package Dashboard does not exist
/Users/fbartolom/Documents/Android/TaxiProfessional/app/src/main/java/info.inarrivo.taxiprofessional/BusyStatus.java
Error:(12, 58) error: interface expected here
Error:(15, 2) error: cannot find symbol class Dashboard
Error:(15, 21) error: cannot find symbol variable Dashboard
Error:(39, 22) error: incompatible types: BusyStatus cannot be converted to UrlConnectionDelegate
Error:(93, 32) error: package Dashboard does not exist
Error:(85, 58) error: cannot find symbol variable Dashboard
Error:(86, 33) error: package Dashboard does not exist
Error:(106, 21) error: package Dashboard does not exist
Error:(106, 65) error: package Dashboard does not exist
Error:(110, 37) error: package Dashboard does not exist
Error:(119, 37) error: package Dashboard does not exist
/Users/fbartolom/Documents/Android/TaxiProfessional/app/src/main/java/info.inarrivo.taxiprofessional/ConfirmedLocalStatus.java
Error:(10, 3) error: cannot find symbol class Dashboard
Error:(10, 22) error: cannot find symbol variable Dashboard
Error:(43, 60) error: cannot find symbol variable NearStatus
/Users/fbartolom/Documents/Android/TaxiProfessional/app/src/main/java/info.inarrivo.taxiprofessional/ConfirmedRemoteStatus.java
Error:(9, 2) error: cannot find symbol class Dashboard
Error:(9, 21) error: cannot find symbol variable Dashboard
Error:(35, 3) error: cannot find symbol class Reservation
Error:(73, 59) error: cannot find symbol variable NearStatus
/Users/fbartolom/Documents/Android/TaxiProfessional/app/src/main/java/info.inarrivo.taxiprofessional/FreeStatus.java
Error:(7, 58) error: interface expected here
Error:(10, 2) error: cannot find symbol class Dashboard
Error:(10, 21) error: cannot find symbol variable Dashboard
Error:(39, 22) error: incompatible types: FreeStatus cannot be converted to UrlConnectionDelegate
/Users/fbartolom/Documents/Android/TaxiProfessional/app/src/main/java/info.inarrivo.taxiprofessional/GCMIntentService.java
Error:(11, 43) error: cannot find symbol class CommonUtilities
Error:(11, 1) error: static import only from classes and interfaces
Error:(12, 43) error: cannot find symbol class CommonUtilities
Error:(12, 1) error: static import only from classes and interfaces
Error:(14, 39) error: cannot find symbol class GCMBaseIntentService
Error:(19, 12) error: cannot find symbol variable SENDER_ID
Error:(25, 2) error: method does not override or implement a method from a supertype
Error:(28, 6) error: cannot find symbol method displayMessage(Context,String)
Error:(36, 2) error: method does not override or implement a method from a supertype
Error:(39, 30) error: cannot find symbol method getString(int)
Error:(46, 2) error: method does not override or implement a method from a supertype
Error:(51, 6) error: cannot find symbol method displayMessage(Context,String)
Error:(59, 2) error: method does not override or implement a method from a supertype
Error:(62, 23) error: cannot find symbol method getString(int,int)
Error:(63, 6) error: cannot find symbol method displayMessage(Context,String)

这是我更新的 build.gradle 文件仍未编译:

buildscript 

dependencies 
    classpath 'com.android.tools.build:gradle:0.11.1'



apply plugin: 'android'
dependencies 
    compile 'com.android.support:appcompat-v7:19.1.0'
    compile 'com.google.android.gms:play-services:4.2.42'
    compile 'org.apache.commons:commons-lang3:3.2.+'

android 
    compileSdkVersion 19
    buildToolsVersion "19.0.0"
    defaultConfig 
    minSdkVersion 19
    targetSdkVersion 19


compileOptions 
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7

而这个显然是Android Studio自主创建的文件:

apply plugin: 'com.android.application'
android 
compileSdkVersion 17
buildToolsVersion "20.0.0"
defaultConfig 
    applicationId 'com.inarrivo.info.taxiprofessional'
    minSdkVersion 15
    targetSdkVersion 20
    versionCode 1
    versionName "1.0"

buildTypes 
    release 
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    

productFlavors 



dependencies 
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-annotations:20.0.0'
compile 'com.android.support:support-v4:20.0.0'
compile 'com.android.support:support-v13:20.0.0'
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'com.android.support:gridlayout-v7:20.0.0'
compile 'com.google.android.gms:play-services:5.2.08'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.google.android.gms:play-services:5.2.08'
compile 'com.google.code.gson:gson:2.2.4'

也没有任何好处。

【问题讨论】:

发布你的 build.gradle 我想我在问题中发布了它。我还应该发布什么以及在哪里可以找到它? 您发布了错误,而不是 build.gradle。您可以在项目的文件夹中找到此文件。 我现在离开了我的开发机器。你能告诉我这个文件的确切路径吗?我会在今晚发布。谢谢。 这是我的 build.gradle 文件。我希望它有助于理解问题。 // ***构建文件,您可以在其中添加所有子项目/模块通用的配置选项。 buildscript repositories jcenter() dependencies classpath 'com.android.tools.build:gradle:0.12.2' // 注意:不要将应用程序依赖项放在这里;它们属于 // 在单个模块 build.gradle 文件中 allprojects repositories jcenter() 【参考方案1】:

您必须重新添加所有依赖项,包括 appcompat。

如果你有所有的jar,你可以把它们放在app的libs/目录下 在应用程序的 build.gradle (projectdir/app/build.gradle) 中使用这样的依赖项时:

compile fileTree(dir: 'libs', include: ['*.jar'])

另一个首选选项是在 Maven 坐标中声明依赖项,如下所示(摘自应用的 build.gradle 文件):

dependencies 
    compile 'com.android.support:appcompat-v7:19.1.0'
    compile 'com.google.android.gms:play-services:4.2.42'
    compile 'org.apache.commons:commons-lang3:3.2.+'

【讨论】:

我真的很抱歉,但我对 Android 开发和 AS 和 Gradle 还很陌生,对 Maven 完全陌生。你能否对我应该做什么更清楚一点。例如,我在哪里可以找到 jar 文件、应用程序的 build.gradle,以及在哪里复制您提到的依赖字符串。另外,一旦发现,我应该将编译器找不到的库放入该依赖列表中,还是在哪里可以找到该列表?感谢您的宝贵时间和热心帮助。 还有一点奇怪的是文件不再能找到其他文件中的类。 @FabrizioBartolomucci 您最好的选择可能是阅读一些 AS 和 Gradle 教程,或者在 Youtube 上观看一些教学视频。您的 jar 文件(如果有)将位于旧项目目录中,通常位于 lib/ 文件夹中。通常,项目使用 Maven 自动下载依赖项。如果您的项目这样做,您将在 pom.xml 文件中找到依赖项列表。应用程序的 build.gradle 默认由 AS 放在 projectdir/app/ 文件夹中。我发布的依赖项块应该放在那个文件中。添加依赖以修复类未找到错误。 重点是我在ios上花了几年的时间学习Android编程花了很多钱,老师决定使用Eclipse。我跟着套件,现在我发现自己的代码包含不起作用。我什至买了一本关于 Android Studio 的新书,但我真的不知道这将如何解决我的问题。相反,我开始按照本书编写一个新的简单程序,也没有任何关于 gradle 的新内容,但它可以工作。 好的,你会成功的!您可能想稍微研究一下依赖管理和 android gradle 插件,tools.android.com/tech-docs/new-build-system/user-guide。 《Gradle in Action》是一本关于构建自动化、依赖管理和 gradle 的好书。【参考方案2】:

我显然搞砸了项目,也许是因为项目标识符。现在我完全复制了我在 Eclispe 中的那个,至少现在错误更友好了。当然我首先要添加到 build.gradle:

dependencies 
     compile fileTree(dir: 'libs', include: ['*.jar'])
     compile 'com.google.android.gms:play-services:+'
     compile 'com.android.support:appcompat-v7:20.+'

如果我无法理解新错误的原因,我会回复你,现在显然主要影响对 R 资源和 GCMRegistrar 的引用。反正今晚,我已经够开心了。

【讨论】:

【参考方案3】:

缺少依赖项会导致此错误。

dependencies 
compile "com.android.support:support-v4:23.1.1"
compile 'com.android.support:support-annotations:23.1.1'

【讨论】:

以上是关于将应用程序从 Eclipse 移植到 Android Studio 时出错的主要内容,如果未能解决你的问题,请参考以下文章

将 Linux 兼容项目从 Windows 移植到 Linux [关闭]

将 Android* x86 NDK 用于 Eclipse* 并移植 NDK 演示样例应用

将Pentaho移植到Eclipse_ee里运行

将 C 编译从 MinGW 移植到 VisualStudio(nmake)

将 Qt 应用程序从 Linux 移植到 Windows

如何将此程序从 conio 移植到 curses?