Android問題集錦之四十六:改包名後出現Error type 3

來源:互聯網
上載者:User

Android問題集錦之四十六:改包名後出現Error type 3

背景:
為了和使用Eclipse的同學並行工作了,我將原Eclipse的項目中加入build.gradle,內容如下:

android {    compileSdkVersion 19    buildToolsVersion "19.1.0"    sourceSets {        main {            manifest.srcFile 'AndroidManifest.xml'            java.srcDirs = ['src']            resources.srcDirs = ['src']            aidl.srcDirs = ['src']            renderscript.srcDirs = ['src']            res.srcDirs = ['res']            assets.srcDirs = ['assets']            jniLibs.srcDirs = ['libs']        }        // Move the tests to tests/java, tests/res, etc...        instrumentTest.setRoot('tests')        debug.setRoot('build-types/debug')        release.setRoot('build-types/release')    }    packagingOptions {        exclude 'META-INF/LICENSE.txt'        exclude 'META-INF/NOTICE.txt'    }    lintOptions {        abortOnError false    }    buildTypes {        debug {            debuggable true            signingConfig signingConfigs.debug        }        release {            debuggable false            signingConfig signingConfigs.debug            minifyEnabled true            proguardFiles 'proguard-project.txt'        }    }}

一直很好的工作著,直到今天我心血來潮將項目的包名在manifest中修改了,也在各個檔案中修改了此包名。編譯通過,但是運行時報錯:

Launching application: com.foo.app/com.foo.app.main.DEVICE SHELL COMMAND: am start -n "com.foo.app/com.foo.app.main"Starting: Intent { cmp=com.foo.app/.main}Error type 3Error: Activity class {com.foo.app/com.foo.app.main} does not exist.

這真是見鬼了,我clean build,並將代碼目錄下的bin也都刪掉了。重啟Android Studio,還是有問題。我也將app從手機中卸載再調試,等等等等。嘗試了很多辦法。stackoverflow那篇文章上的方法也嘗試了許多。

當然,我知道建立一個項目並將此項目中的檔案拷過去,一定能夠運行。但我不想這麼做。

最後,還是參考網友,將build.gradle中android下加入applicationId為新包名,解決了這個問題。

  defaultConfig {    applicationId "com.yourpackage.yourapplication"  }

參考:
http://stackoverflow.com/questions/7071271/activity-class-does-not-exist

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.