- Android studio 引用某個 module 后編譯報錯找不到此 module , 是因為此 module (名字是 ModuleApp) 里 ModuleApp.iml 文件丟失導致。解決辦法是:
- 找到工程的settings.gradle文件
- 在里邊添加moudle的名字
include ‘:ModuleApp’, ‘:commonlibrary’, ‘:colordialog’,’creditandloanappu’ - 重新 clean 下應該就可以了。
- Unable to instantiate fragment 的問題:
開發(fā)登錄 sdk 使用 DialogFragment 時在初始化完對話框后切屏,會出現閃退。查看錯誤是 Unable to instantiate fragment com.wonderfull.mobileshop.g.a.a: could not find Fragment constructor 的問題,是說fragment不能被實例化,那么問題來了,為什么不能被實例化呢,首先,fragment什么時候會被實例化,當然是我們在代碼中去add或者replace這個fragment的時候,除此以為還有什么地方去實例化fragment嗎,有,宿主Activity被銷毀后重新恢復的時候,它的fragment也會被恢復,進行重新實例化,這是由系統來完成的,通過反射機制。切屏的時候就相當于宿主 Activity 被銷毀后重新恢復,此時 Fragmet 也要重新恢復并實例化。
好,說到這,去瞅瞅源碼,我們看看fragment的構造函數:
/**
* Default constructor. <strong>Every</strong> fragment must have an
* empty constructor, so it can be instantiated when restoring its
* activity's state. It is strongly recommended that subclasses do not
* have other constructors with parameters, since these constructors
* will not be called when the fragment is re-instantiated; instead,
* arguments can be supplied by the caller with {@link #setArguments}
* and later retrieved by the Fragment with {@link #getArguments}.
*
* <p>Applications should generally not implement a constructor. Prefer
* {@link #onAttach(Context)} instead. It is the first place application code can run where
* the fragment is ready to be used - the point where the fragment is actually associated with
* its context. Some applications may also want to implement {@link #onInflate} to retrieve
* attributes from a layout resource, although note this happens when the fragment is attached.
*/
public Fragment() {
}
仔細看函數注解,大概意思是:
“強烈推薦fragment的繼承類不要去實現帶參的構造函數,因為這些帶參構造函數在fragment被再次實例化的時候將不會被調用,那么這些參數也就丟失,建議通過setArguments方式進行參數傳遞?!?/p>
其實這段話還有一層意思,既然在再次實例化的時候不會調用我們聲明的帶參構造函數,那么必然調用了無參構造函數,問題來了,如果你滿足了下面兩個條件:
- 為自己的fragment添加了帶有參數的構造器
- 沒有額外聲明一個無參的構造函數,或者聲明了,但是是private的
那么就悲催了,因為你無意間覆蓋了無參構造函數,是的,這樣就會報上面那個異常,通過檢查代碼,確實犯了這個問題,莫名其妙的聲明了一個private類型的fragmeng空構造器,那么問題也就不可避免了,之所以說這個問題難遇到,是因為我們平常確實很少去為fragment聲明其他的構造器。
- 有時編譯項目會遇到 Manifest merger failed with multiple errors, see logs 這種錯誤,但是看 log 日志又沒有任何提示信息,此時可以通過以下命令去查看錯誤信息,在 Android Studio 終端 terminal 里輸入:
gradlew processDebugManifest --stacktrace
注意如果是 mac 電腦,需要在 gradlew 前加 ./ 表示以管理員命令運行
./gradlew processDebugManifest --stacktrace
其中,processDebugManifest是log里面提到的,這個命令會去獲取更多的log信息。

圖中可見是我項目的最小 sdk 版本是14,而使用的依賴庫要求的最小版本是16,把我項目的 minSdkVersion 改成16 就可以了。
參考來源,感謝此作者提供的幫助 。
Android SDK位置查看:
Tools-Android-SDK Manager (默認位置:/Users/XXXXXX/Library/Android/sdk)
默認位置查找:
右鍵Finder-前往文件夾 輸入 ~/資源庫(或 ~/Library) 注:Library默認隱藏了。Android Studio 移除引入的谷歌gms service庫后編譯報錯 error: failed processing manifest.
可以清除編譯緩存來解決。
清除編譯gradle cache方法:參考
cleared the cache using this command:
rm -rf $HOME/.gradle/caches/
also I cleared the build dir running
./gradlew cleanBuildCache
and manually deleted the build dir
the I did run assable again and the apk got generated OK worked :)
./gradlew assemble