Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在lib的java代码中引用Small时,开启代码混淆,编译时产生混淆警告导致编译失败 #158

Closed
jayzhou215 opened this issue May 25, 2016 · 6 comments

Comments

@jayzhou215
Copy link

背景:实际工程中需要在lib的java文件中引用Small的相关类,在lib中开启代码混淆后出现找不到Samll引用。下面是情景还原。

操作:lib.utils/build.gradle 打开代码混淆

buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), '../app/proguard-rules.pro'
        }
    }

修改:UIUtiles.java,引入Small.getContext()

    public static void showToast(Context context, String tips) {
        Toast toast = Toast.makeText(Small.getContext(), "lib.utils: " + tips, Toast.LENGTH_SHORT);
        toast.show();
    }

    public static void alert(Context context, String tips) {
        AlertDialog dlg = new AlertDialog.Builder(Small.getContext())
                .setMessage("lib.utils: " + tips)
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                })
                .create();
        dlg.show();
    }

结果:提示需要修复此处warning才能继续

Warning: net.wequick.example.small.lib.utils.UIUtils: can't find referenced class net.wequick.small.Small
Warning: net.wequick.example.small.lib.utils.UIUtils: can't find referenced class net.wequick.small.Small

问题:为何会出现Small类找不到的情况,求助!

完整的日志

./gradlew buildLib
Incremental java compilation is an incubating feature.
:buildLib
:app:preBuild
[Small] building library 1 of 3 - app (0x7f)
:app:preWequickReleaseBuild
:app:checkWequickReleaseManifest
:app:preWequickDebugBuild
:app:prepareComAndroidSupportAnimatedVectorDrawable2321Library
:app:prepareComAndroidSupportAppcompatV72321Library
:app:prepareComAndroidSupportDesign2321Library
:app:prepareComAndroidSupportRecyclerviewV72321Library
:app:prepareComAndroidSupportSupportV42321Library
:app:prepareComAndroidSupportSupportVectorDrawable2321Library
:app:prepareNetWequickSmallSmall100Beta2Library
:app:prepareWequickReleaseDependencies
:app:compileWequickReleaseAidl
:app:compileWequickReleaseRenderscript
:app:generateWequickReleaseBuildConfig
:app:generateWequickReleaseAssets UP-TO-DATE
:app:mergeWequickReleaseAssets
:app:generateWequickReleaseResValues UP-TO-DATE
:app:generateWequickReleaseResources
:app:mergeWequickReleaseResources
:app:processWequickReleaseManifest
:app:processWequickReleaseResources
:app:generateWequickReleaseSources
:app:compileWequickReleaseJavaWithJavac
:app:jarWequickReleaseClasses
:app:buildLib
:lib.style:preBuild
[Small] building library 2 of 3 - lib.style (0x79)
:lib.style:preReleaseBuild
:lib.style:checkReleaseManifest
:lib.style:preDebugBuild
:lib.style:prepareComAndroidSupportAnimatedVectorDrawable2321Library
:lib.style:prepareComAndroidSupportAppcompatV72321Library
:lib.style:prepareComAndroidSupportSupportV42321Library
:lib.style:prepareComAndroidSupportSupportVectorDrawable2321Library
:lib.style:prepareReleaseDependencies
:lib.style:compileReleaseAidl
:lib.style:compileReleaseRenderscript
:lib.style:generateReleaseBuildConfig
:lib.style:generateReleaseAssets UP-TO-DATE
:lib.style:mergeReleaseAssets
:lib.style:generateReleaseResValues UP-TO-DATE
:lib.style:generateReleaseResources
:lib.style:mergeReleaseResources
:lib.style:processReleaseManifest
:lib.style:processReleaseResources
  [lib.style] split library res files...                   [  OK  ]
  [lib.style] slice asset package and reset package id...  [  OK  ]
  [lib.style] split library R.java files...                [  OK  ]
:lib.style:generateReleaseSources
:lib.style:compileReleaseJavaWithJavac
[ant:javac] : warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[ant:javac] 警告: [options] 未与 -source 1.7 一起设置引导类路径
[ant:javac] 1 个警告
  [lib.style] split R.class...                             [  OK  ]
:lib.style:compileReleaseNdk UP-TO-DATE
:lib.style:compileReleaseSources
:lib.style:lintVitalRelease
:lib.style:prePackageMarkerForRelease
:lib.style:transformClassesWithDexForRelease
  [lib.style] split aar classes...                         [  OK  ]
:lib.style:mergeReleaseJniLibFolders
:lib.style:transformNative_libsWithMergeJniLibsForRelease
:lib.style:processReleaseJavaRes UP-TO-DATE
:lib.style:transformResourcesWithMergeJavaResForRelease
:lib.style:validateReleaseSigning
:lib.style:packageRelease
:lib.style:zipalignRelease
:lib.style:assembleRelease
  -- output: armeabi/libcom_example_mysmall_lib_style.so (4447 bytes = 4.3 KB)
:lib.style:buildLib
:lib.utils:preBuild
[Small] building library 3 of 3 - lib.utils (0x73)
:lib.utils:preReleaseBuild
:lib.utils:checkReleaseManifest
:lib.utils:preDebugBuild
:lib.utils:prepareComAndroidSupportAnimatedVectorDrawable2321Library
:lib.utils:prepareComAndroidSupportAppcompatV72321Library
:lib.utils:prepareComAndroidSupportSupportV42321Library
:lib.utils:prepareComAndroidSupportSupportVectorDrawable2321Library
:lib.utils:prepareReleaseDependencies
:lib.utils:compileReleaseAidl
:lib.utils:compileReleaseRenderscript
:lib.utils:generateReleaseBuildConfig
:lib.utils:generateReleaseAssets UP-TO-DATE
:lib.utils:mergeReleaseAssets
:lib.utils:generateReleaseResValues UP-TO-DATE
:lib.utils:generateReleaseResources
:lib.utils:mergeReleaseResources
:lib.utils:processReleaseManifest
:lib.utils:processReleaseResources
  [lib.utils] split library res files...                   [  OK  ]
  [lib.utils] slice asset package and reset package id...  [  OK  ]
  [lib.utils] split library R.java files...                [  OK  ]
:lib.utils:generateReleaseSources
:lib.utils:compileReleaseJavaWithJavac
[ant:javac] : warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[ant:javac] 警告: [options] 未与 -source 1.7 一起设置引导类路径
[ant:javac] 1 个警告
  [lib.utils] split R.class...                             [  OK  ]
:lib.utils:compileReleaseNdk UP-TO-DATE
:lib.utils:compileReleaseSources
:lib.utils:lintVitalRelease
:lib.utils:prePackageMarkerForRelease
:lib.utils:processReleaseJavaRes UP-TO-DATE
:lib.utils:transformResourcesWithMergeJavaResForRelease
:lib.utils:transformClassesAndResourcesWithProguardForRelease
ProGuard, version 5.2.1
Reading input...
Reading program jar [/Users/xxx/git/Small/Android/Sample/lib.utils/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.2.1/jars/classes.jar] (filtered)
Reading program jar [/Users/xxx/git/Small/Android/Sample/lib.utils/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/23.2.1/jars/classes.jar] (filtered)
Reading program jar [/Users/xxx/git/Small/Android/Sample/lib.utils/build/intermediates/exploded-aar/com.android.support/support-vector-drawable/23.2.1/jars/classes.jar] (filtered)
Reading program jar [/Users/xxx/git/Small/Android/Sample/lib.utils/build/intermediates/exploded-aar/com.android.support/support-v4/23.2.1/jars/classes.jar] (filtered)
Reading program jar [/Users/xxx/git/Small/Android/Sample/lib.utils/build/intermediates/exploded-aar/com.android.support/support-v4/23.2.1/jars/libs/internal_impl-23.2.1.jar] (filtered)
Reading program directory [/Users/xxx/git/Small/Android/Sample/lib.utils/build/intermediates/classes/release] (filtered)
Reading library jar [/Users/xxx/Library/Android/sdk/platforms/android-23/android.jar]
Reading library jar [/Users/xxx/Library/Android/sdk/platforms/android-23/optional/org.apache.http.legacy.jar]
Note: duplicate definition of library class [android.net.http.SslCertificate]
Note: duplicate definition of library class [android.net.http.SslError]
Note: duplicate definition of library class [android.net.http.SslCertificate$DName]
Note: duplicate definition of library class [org.apache.http.conn.scheme.SocketFactory]
Note: duplicate definition of library class [org.apache.http.conn.scheme.HostNameResolver]
Note: duplicate definition of library class [org.apache.http.conn.ConnectTimeoutException]
Note: duplicate definition of library class [org.apache.http.params.HttpParams]
Note: there were 7 duplicate class definitions.
      (http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)
Initializing...
Note: the configuration refers to the unknown class 'net.wequick.small.Small'
Note: the configuration refers to the unknown class 'net.wequick.small.Bundle'
      Maybe you meant the fully qualified name 'android.os.Bundle'?
Warning: net.wequick.example.small.lib.utils.UIUtils: can't find referenced class net.wequick.small.Small
Warning: net.wequick.example.small.lib.utils.UIUtils: can't find referenced class net.wequick.small.Small
Note: there were 2 references to unknown classes.
      You should check your configuration for typos.
      (http://proguard.sourceforge.net/manual/troubleshooting.html#unknownclass)
Warning: there were 2 unresolved references to classes or interfaces.
         You may need to add missing library jars or update their versions.
         If your code works fine without the missing classes, you can suppress
         the warnings with '-dontwarn' options.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning: Exception while processing task java.io.IOException: Please correct the above warnings first.
:lib.utils:transformClassesAndResourcesWithProguardForRelease FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':lib.utils:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: Please correct the above warnings first.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 10.518 secs
@galenlin
Copy link
Member

插件模块暂不支持混淆

@jayzhou215
Copy link
Author

3qs! 我想继续研究这个问题,有什么思路上的意见吗?感谢!

@galenlin
Copy link
Member

你这个报错是因为混淆的时候没有加入Small的jar包,可能需要在transformClassesAndResourcesWithProguardForRelease做些操作。

但这个解决了还不够,关于插件的混淆讨论见 #85

@galenlin
Copy link
Member

gradle-small:0.9.0 已支持混淆,关闭本问题

@gordonpro
Copy link

@galenlin 你好,请问 gradle-small:0.9.0 是插件也支持混淆了吗?

@galenlin
Copy link
Member

galenlin commented Sep 8, 2016

@gordonpro 是的,在那之后的版本都已经支持

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants