问:
Instant App module searches for resources in another not base module
I'm developing an Instant App, that has base module and 2 feature modules: feature1 and feature2. I'm getting strange crash when I'm trying to launch feature2 activity:

```    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.myapp.qa/com.test.myapp.feature2.ui.activity.Feature2Activity}: android.view.InflateException: Binary XML file line #76: Binary XML file line #76: Error inflating class android.widget.ProgressBar
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                                at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                at android.os.Looper.loop(Looper.java:164)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                             Caused by: android.view.InflateException: Binary XML file line #76: Binary XML file line #76: Error inflating class android.widget.ProgressBar
                                                                             Caused by: android.view.InflateException: Binary XML file line #76: Error inflating class android.widget.ProgressBar
                                                                             Caused by: java.lang.reflect.InvocationTargetException
                                                                                at java.lang.reflect.Constructor.newInstance0(Native Method)
                                                                                at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
                                                                                at android.view.LayoutInflater.createView(LayoutInflater.java:650)
                                                                                at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
                                                                                at android.view.LayoutInflater.onCreateView(LayoutInflater.java:723)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:791)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                                at com.test.myapp.ui.activity.base.BaseActivity.setContentView(BaseActivity.java:237)
                                                                                at com.test.myapp.feature2.ui.activity.Feature2Activity.onCreate(Feature2Activity.java:123)
                                                                                at android.app.Activity.performCreate(Activity.java:6980)
                                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                                at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                at android.os.Looper.loop(Looper.java:164)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                             Caused by: android.content.res.Resources$NotFoundException: Drawable com.test.myapp.qa:layout/random_feature1_layout with resource ID #0x82030011
E/AndroidRuntime: Caused by: android.content.res.Resources$NotFoundException: File res/layout/random_feature1_layout_fns.xml from drawable resource ID #0x82030011
                                                                                at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:754)
                                                                                at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:598)
                                                                                at android.content.res.Resources.loadDrawable(Resources.java:885)
                                                                                at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:953)
                                                                                at android.content.res.TypedArray.getDrawable(TypedArray.java:928)
                                                                                at android.widget.ProgressBar.<init>(ProgressBar.java:281)
                                                                                at android.widget.ProgressBar.<init>(ProgressBar.java:230)
                                                                                at android.widget.ProgressBar.<init>(ProgressBar.java:226)
                                                                                at java.lang.reflect.Constructor.newInstance0(Native Method)
                                                                                at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
                                                                                at android.view.LayoutInflater.createView(LayoutInflater.java:650)
                                                                                at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
                                                                                at android.view.LayoutInflater.onCreateView(LayoutInflater.java:723)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:791)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                                at com.test.myapp.ui.activity.base.BaseActivity.setContentView(BaseActivity.java:237)
                                                                                at com.test.myapp.feature2.ui.activity.Feature2Activity.onCreate(Feature2Activity.java:123)
                                                                                at android.app.Activity.performCreate(Activity.java:6980)
                                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                                at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                at android.os.Looper.loop(Looper.java:164)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                             Caused by: android.view.InflateException: Class not found LinearLayout
                                                                                at android.graphics.drawable.DrawableInflater.inflateFromClass(DrawableInflater.java:220)
                                                                                at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:139)
                                                                                at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1295)
                                                                                at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1254)
                                                                                at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:744)
                                                                                at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:598)
                                                                                at android.content.res.Resources.loadDrawable(Resources.java:885)
                                                                                at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:953)
                                                                                at android.content.res.TypedArray.getDrawable(TypedArray.java:928)
                                                                                at android.widget.ProgressBar.<init>(ProgressBar.java:281)
                                                                                at android.widget.ProgressBar.<init>(ProgressBar.java:230)
                                                                                at android.widget.ProgressBar.<init>(ProgressBar.java:226)
                                                                                at java.lang.reflect.Constructor.newInstance0(Native Method)
                                                                                at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
                                                                                at android.view.LayoutInflater.createView(LayoutInflater.java:650)
                                                                                at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
                                                                                at android.view.LayoutInflater.onCreateView(LayoutInflater.java:723)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:791)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                                at com.test.myapp.ui.activity.base.BaseActivity.setContentView(BaseActivity.java:237)
                                                                                at com.test.myapp.feature2.ui.activity.Feature2Activity.onCreate(Feature2Activity.java:123)
                                                                                at android.app.Activity.performCreate(Activity.java:6980)
                                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                                at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                at android.os.Looper.loop(Looper.java:164)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
    06-18 10:42:37.616 11607-11607/com.test.myapp.qa E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "LinearLayout" on path: DexPathList[[zip file "/data/app/com.test.myapp.qa-ncO99Ptagbu_PYoBeZhFeA==/base.apk", zip file "/data/app/com.test.myapp.qa-ncO99Ptagbu_PYoBeZhFeA==/split_feature2.apk", zip file "/data/app/com.test.myapp.qa-ncO99Ptagbu_PYoBeZhFeA==/split_feature1.apk"],nativeLibraryDirectories=[/data/app/com.test.myapp.qa-ncO99Ptagbu_PYoBeZhFeA==/lib/x86, /system/lib, /system/vendor/lib]]
                                                                                at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
                                                                                at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                                                                                at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                                at android.graphics.drawable.DrawableInflater.inflateFromClass(DrawableInflater.java:201)
                                                                                ... 47
```

<p>If we look at <code>Feature2Activity</code> layout file, line 76 we'll see:</p>

```<ProgressBar
    android:layout_width="20dp"
    android:layout_height="20dp"
    android:layout_gravity="right"
    android:indeterminateDrawable="@drawable/progress" />
```

<p>Drawable <code>progress.xml</code> is located in <code>feature2</code> resources. If we remove it, or change it to some drawable from <code>base</code> resources, everything works fine.</p>

<p>Another strange thing is this line:</p>

```Caused by: android.content.res.Resources$NotFoundException: Drawable com.test.myapp.qa:layout/random_feature1_layout with resource ID #0x82030011
```

<p>Layout <code>random_feature1_layout</code> is located at <code>feature1</code> resources, and shouldn't be referenced at all. But if we go to <code>feature2\R.java</code> file, and look for <code>progress.xml</code> drawable we'll find:</p>

```public static final int progress=0x80030011;
```

And if you look closer you'll notice that progress's and random_feature1_layout's ids are differ by one digit: 0x80030011 and 0x82030011. So I made an assumption, that feature2 for unknown reasons looks for progress drawable in feature1 resources. I tried to remove feature1 dependency and crash disappeared, that confirms my assumption.

I should also note that this issue is observed only for Instant app. Installed app works fine.

My question is how is it possible that feature2 searches for resources in feature1 apk? Do you have any ideas what caused this behaviour or maybe hints how to debug this issue?

答:
With reference to  Google issue tracker, it has been fixed with Android SDK Built-Tools to 27.0.2

Please update your Android SDK Built-Tools to 27.0.2
And ensure you are on Android Studio 3.0.1 or newer.

If any issue persists, please report at Google issue tracker they will re-open to examine. Thanks!

Body:
I'm developing an Instant App, that has base module and 2 feature modules: feature1 and feature2. I'm getting strange crash when I'm trying to launch feature2 activity:

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.myapp.qa/com.test.myapp.feature2.ui.activity.Feature2Activity}: android.view.InflateException: Binary XML file line #76: Binary XML file line #76: Error inflating class android.widget.ProgressBar
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                                at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                at android.os.Looper.loop(Looper.java:164)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                             Caused by: android.view.InflateException: Binary XML file line #76: Binary XML file line #76: Error inflating class android.widget.ProgressBar
                                                                             Caused by: android.view.InflateException: Binary XML file line #76: Error inflating class android.widget.ProgressBar
                                                                             Caused by: java.lang.reflect.InvocationTargetException
                                                                                at java.lang.reflect.Constructor.newInstance0(Native Method)
                                                                                at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
                                                                                at android.view.LayoutInflater.createView(LayoutInflater.java:650)
                                                                                at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
                                                                                at android.view.LayoutInflater.onCreateView(LayoutInflater.java:723)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:791)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                                at com.test.myapp.ui.activity.base.BaseActivity.setContentView(BaseActivity.java:237)
                                                                                at com.test.myapp.feature2.ui.activity.Feature2Activity.onCreate(Feature2Activity.java:123)
                                                                                at android.app.Activity.performCreate(Activity.java:6980)
                                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                                at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                at android.os.Looper.loop(Looper.java:164)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                             Caused by: android.content.res.Resources$NotFoundException: Drawable com.test.myapp.qa:layout/random_feature1_layout with resource ID #0x82030011
E/AndroidRuntime: Caused by: android.content.res.Resources$NotFoundException: File res/layout/random_feature1_layout_fns.xml from drawable resource ID #0x82030011
                                                                                at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:754)
                                                                                at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:598)
                                                                                at android.content.res.Resources.loadDrawable(Resources.java:885)
                                                                                at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:953)
                                                                                at android.content.res.TypedArray.getDrawable(TypedArray.java:928)
                                                                                at android.widget.ProgressBar.<init>(ProgressBar.java:281)
                                                                                at android.widget.ProgressBar.<init>(ProgressBar.java:230)
                                                                                at android.widget.ProgressBar.<init>(ProgressBar.java:226)
                                                                                at java.lang.reflect.Constructor.newInstance0(Native Method)
                                                                                at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
                                                                                at android.view.LayoutInflater.createView(LayoutInflater.java:650)
                                                                                at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
                                                                                at android.view.LayoutInflater.onCreateView(LayoutInflater.java:723)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:791)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                                at com.test.myapp.ui.activity.base.BaseActivity.setContentView(BaseActivity.java:237)
                                                                                at com.test.myapp.feature2.ui.activity.Feature2Activity.onCreate(Feature2Activity.java:123)
                                                                                at android.app.Activity.performCreate(Activity.java:6980)
                                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                                at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                at android.os.Looper.loop(Looper.java:164)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                             Caused by: android.view.InflateException: Class not found LinearLayout
                                                                                at android.graphics.drawable.DrawableInflater.inflateFromClass(DrawableInflater.java:220)
                                                                                at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:139)
                                                                                at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1295)
                                                                                at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1254)
                                                                                at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:744)
                                                                                at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:598)
                                                                                at android.content.res.Resources.loadDrawable(Resources.java:885)
                                                                                at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:953)
                                                                                at android.content.res.TypedArray.getDrawable(TypedArray.java:928)
                                                                                at android.widget.ProgressBar.<init>(ProgressBar.java:281)
                                                                                at android.widget.ProgressBar.<init>(ProgressBar.java:230)
                                                                                at android.widget.ProgressBar.<init>(ProgressBar.java:226)
                                                                                at java.lang.reflect.Constructor.newInstance0(Native Method)
                                                                                at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
                                                                                at android.view.LayoutInflater.createView(LayoutInflater.java:650)
                                                                                at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
                                                                                at android.view.LayoutInflater.onCreateView(LayoutInflater.java:723)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:791)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                                at com.test.myapp.ui.activity.base.BaseActivity.setContentView(BaseActivity.java:237)
                                                                                at com.test.myapp.feature2.ui.activity.Feature2Activity.onCreate(Feature2Activity.java:123)
                                                                                at android.app.Activity.performCreate(Activity.java:6980)
                                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                                at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                at android.os.Looper.loop(Looper.java:164)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
    06-18 10:42:37.616 11607-11607/com.test.myapp.qa E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "LinearLayout" on path: DexPathList[[zip file "/data/app/com.test.myapp.qa-ncO99Ptagbu_PYoBeZhFeA==/base.apk", zip file "/data/app/com.test.myapp.qa-ncO99Ptagbu_PYoBeZhFeA==/split_feature2.apk", zip file "/data/app/com.test.myapp.qa-ncO99Ptagbu_PYoBeZhFeA==/split_feature1.apk"],nativeLibraryDirectories=[/data/app/com.test.myapp.qa-ncO99Ptagbu_PYoBeZhFeA==/lib/x86, /system/lib, /system/vendor/lib]]
                                                                                at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
                                                                                at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                                                                                at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                                at android.graphics.drawable.DrawableInflater.inflateFromClass(DrawableInflater.java:201)
                                                                                ... 47

If we look at Feature2Activity layout file, line 76 we'll see:

<ProgressBar
    android:layout_width="20dp"
    android:layout_height="20dp"
    android:layout_gravity="right"
    android:indeterminateDrawable="@drawable/progress" />

Drawable progress.xml is located in feature2 resources. If we remove it, or change it to some drawable from base resources, everything works fine.

Another strange thing is this line:

Caused by: android.content.res.Resources$NotFoundException: Drawable com.test.myapp.qa:layout/random_feature1_layout with resource ID #0x82030011

Layout random_feature1_layout is located at feature1 resources, and shouldn't be referenced at all. But if we go to feature2\R.java file, and look for progress.xml drawable we'll find:

public static final int progress=0x80030011;

And if you look closer you'll notice that progress's and random_feature1_layout's ids are differ by one digit: 0x80030011 and 0x82030011. So I made an assumption, that feature2 for unknown reasons looks for progress drawable in feature1 resources. I tried to remove feature1 dependency and crash disappeared, that confirms my assumption.

I should also note that this issue is observed only for Instant app. Installed app works fine.

My question is how is it possible that feature2 searches for resources in feature1 apk? Do you have any ideas what caused this behaviour or maybe hints how to debug this issue?


来源: stackexchange

问:
How to use TypeORM to add new node to a node that already has children using table closure?
I'm trying to use typeorm and follow this example to deal with hierarchical data structure the example is only about how to create a hierarchy table and read it's path but what about when already we have a node that has children and we want to add more children to I believe we should be able to push something like this:

category.children.push(newCategory);
```
<p>but category.children is empty while it has children.</p>
<p>Edit1:</p>
<p>Here is the code:</p>
<pre class="lang-js prettyprint-override"><code>async function test() {
    let connection = await createConnection(options);
    let categoryRepository = connection.getTreeRepository(Category);
    let cat = await categoryRepository.findOneById(4, {
        relations: ['children']
    });
    console.log(JSON.stringify(cat));
    let childChildCategory1 = new Category();
    childChildCategory1.name = "Child #1 of Child #1 of Category #11111";
    childChildCategory1.description = "Child #1 of Child #1 of Category #11111";
    cat["__children__"].push(childChildCategory1)
    await categoryRepository.save(cat);
    let result = await categoryRepository.findDescendants(cat);
    console.log(JSON.stringify(result));
}
</code>```

and here is the result:
The first console.log:

```<code>{
    "id":4,
        "name":"Child #2 of Category #1",
            "description":"Child #2 of Category #1",
                "level":2,
                    "__children__":[
                        { "id": 5, "name": "Child #1 of Child #2 of Category #1", "description": "Child #1 of Child #2 of Category #1", "level": 3 },
                        { "id": 6, "name": "Child #1 of Child #1 of Category #11111", "description": "Child #1 of Child #1 of Category #11111", "level": 3 },
                        { "id": 7, "name": "Child #1 of Child #1 of Category #11111", "description": "Child #1 of Child #1 of Category #11111", "level": 3 }
                    ],
                        "__has_children__":true
}
</code>```

The second console.log:

```<code>[
    { "id": 4, "name": "Child #2 of Category #1", "description": "Child
    #2 of Category #1", "level": 2 },
    { "id": 5, "name": "Child #1 of Child #2 of Category #1",
    "description": "Child #1 of Child #2 of Category #1", "level": 3 },
    { "id": 6, "name": "Child #1 of Child #1 of Category #11111",
    "description": "Child #1 of Child #1 of Category #11111", "level":
    3 },
    { "id": 7, "name": "Child #1 of Child #1 of Category #11111",
    "description": "Child #1 of Child #1 of Category #11111", "level":
    3 },
    { "id": 8, "name": "Child #1 of Child #1 of Category #11111",
    "description": "Child #1 of Child #1 of Category #11111", "level":
    3 }
]
</code>```

答: Did you put { cascadeInsert: true, cascadeUpdate: true } options on @TreeChildren() decorator ? How do you load the category ? If you load it through QueryBuilder, you may forgot join the chidrens with leftJoinAndSelect method.

ContentLicense: CC BY-SA 4.0

Body:
I'm trying to use typeorm and follow this example to deal with hierarchical data structure the example is only about how to create a hierarchy table and read it's path but what about when already we have a node that has children and we want to add more children to I believe we should be able to push something like this:

category.children.push(newCategory);

but category.children is empty while it has children.

Edit1:

Here is the code:

async function test() {
    let connection = await createConnection(options);
    let categoryRepository = connection.getTreeRepository(Category);
    let cat = await categoryRepository.findOneById(4, {
        relations: ['children']
    });
    console.log(JSON.stringify(cat));
    let childChildCategory1 = new Category();
    childChildCategory1.name = "Child #1 of Child #1 of Category #11111";
    childChildCategory1.description = "Child #1 of Child #1 of Category #11111";
    cat["__children__"].push(childChildCategory1)
    await categoryRepository.save(cat);
    let result = await categoryRepository.findDescendants(cat);
    console.log(JSON.stringify(result));
}

and here is the result:
The first console.log:

{
    "id":4,
        "name":"Child #2 of Category #1",
            "description":"Child #2 of Category #1",
                "level":2,
                    "__children__":[
                        { "id": 5, "name": "Child #1 of Child #2 of Category #1", "description": "Child #1 of Child #2 of Category #1", "level": 3 },
                        { "id": 6, "name": "Child #1 of Child #1 of Category #11111", "description": "Child #1 of Child #1 of Category #11111", "level": 3 },
                        { "id": 7, "name": "Child #1 of Child #1 of Category #11111", "description": "Child #1 of Child #1 of Category #11111", "level": 3 }
                    ],
                        "__has_children__":true
}

The second console.log:

[
    { "id": 4, "name": "Child #2 of Category #1", "description": "Child
    #2 of Category #1", "level": 2 },
    { "id": 5, "name": "Child #1 of Child #2 of Category #1",
    "description": "Child #1 of Child #2 of Category #1", "level": 3 },
    { "id": 6, "name": "Child #1 of Child #1 of Category #11111",
    "description": "Child #1 of Child #1 of Category #11111", "level":
    3 },
    { "id": 7, "name": "Child #1 of Child #1 of Category #11111",
    "description": "Child #1 of Child #1 of Category #11111", "level":
    3 },
    { "id": 8, "name": "Child #1 of Child #1 of Category #11111",
    "description": "Child #1 of Child #1 of Category #11111", "level":
    3 }
]

ContentLicense: CC BY-SA 3.0


问:
Fibonacci sequence in Haskell
I am trying to build a fibonacci wrapper function that takes in multiple command line arguments and computes the associated Fibonacci number for each argument</p>

答:
You should use the read or readMaybe functions to get an Int from the String:

```<code>fibonacci_wrapper :: [String] -> Maybe Int
fibonacci_wrapper (x:_) =
    case readMaybe x of
        Just n -> Just (fibonacci n)
        Nothing -> Nothing -- read failed
-- Not enough args
fibonacci_wrapper _ = Nothing
</code>```

However, if you want to take multiple arguments, you should return the rest of the argument list along with the Int result so that you can continue consuming arguments.

Title: Fibonacci sequence in Haskell

Body:
You should use the read or readMaybe functions to get an Int from the String:

fibonacci_wrapper :: [String] -> Maybe Int
fibonacci_wrapper (x:_) =
    case readMaybe x of
        Just n -> Just (fibonacci n)
        Nothing -> Nothing -- read failed
-- Not enough args
fibonacci_wrapper _ = Nothing

However, if you want to take multiple arguments, you should return the rest of the argument list along with the Int result so that you can continue consuming arguments.


问:
Two fetchColumns next to each other not working
I want to fetch two different specific columns and I have already tested this and  it clearly shows that the second fetchColumn doesn't work because I've tried to echo it but it only echoes the first fetchColumn

This is the code:

```<code>$stmt = $pdo->prepare('SELECT * FROM logins WHERE login_name = :username');
$criteria = ['username' => $_POST['Username']];
$stmt->execute($criteria);
$user = $stmt->fetchColumn(1);
$admin = $stmt->fetchColumn(6);
if (password_verify($_POST['Password'], $user) && !empty($admin)) {
    $_SESSION['adminlogin'] = true;
    $_SESSION['loggedin'] = true;
    $_SESSION['adminloginname'] = $_POST['Username'];
    header('location: adminpage.php');
}
elseif (password_verify($_POST['Password'], $user)) {
    $_SESSION['loggedin'] = true;
    $_SESSION['username'] = $_POST['Username'];
    header('location: latestarticles.php');
    } else {
        echo '<p> Wrong password </p>';
    }
}
</code>```

I want this code to check if the $admin variable has a value or not, if it does then you get admin rights if not then you get normal user rights. But the $admin = $stmt->fetchColumn(6); doesn't show any results.

UPDATE: One thing that I have just tried was adding another search query beneath the first fetchColumn, it works but surely this can't be the only way, there has to be something easier.
My code looks like this now:

```<code>$stmt = $pdo->prepare('SELECT * FROM logins WHERE login_name = :username');
$criteria = ['username' => $_POST['Username']];
$stmt->execute($criteria);
$user = $stmt->fetchColumn(1);
$stmt = $pdo->prepare('SELECT * FROM logins WHERE login_name = :username');
$criteria = ['username' => $_POST['Username']];
$stmt->execute($criteria);
$admin = $stmt->fetchColumn(6);
if (password_verify($_POST['Password'], $user) && !empty($admin)) {
    $_SESSION['adminlogin'] = true;
    $_SESSION['loggedin'] = true;
    $_SESSION['adminloginname'] = $_POST['Username'];
    header('location: adminpage.php');
}
 elseif (password_verify($_POST['Password'], $user)) {
    $_SESSION['loggedin'] = true;
    $_SESSION['username'] = $_POST['Username'];
    header('location: latestarticles.php');
    } else {
        echo '<p> Wrong password </p>';
    }
</code>```

答:
php manual says:

(1) fetchColumn() should not be used to retrieve boolean columns, as it is
  impossible to distinguish a value of FALSE from there being no more
  rows to retrieve

(2) There is no way to return another column from the same row if
  you use PDOStatement::fetchColumn() to retrieve data.

Instead you could do this with fetch() method as shown below:

```<code>$result = $stmt->fetch(PDO::FETCH_ASSOC);
$user = $result['user_column'];
$admin = $result['admin_column'];
</code>```

Here is the PHP manual reference: http://php.net/manual/en/pdostatement.fetch.php

Body:
I want to fetch two different specific columns and I have already tested this and  it clearly shows that the second fetchColumn doesn't work because I've tried to echo it but it only echoes the first fetchColumn

This is the code:

$stmt = $pdo->prepare('SELECT * FROM logins WHERE login_name = :username');
$criteria = ['username' => $_POST['Username']];
$stmt->execute($criteria);
$user = $stmt->fetchColumn(1);
$admin = $stmt->fetchColumn(6);
if (password_verify($_POST['Password'], $user) && !empty($admin)) {
    $_SESSION['adminlogin'] = true;
    $_SESSION['loggedin'] = true;
    $_SESSION['adminloginname'] = $_POST['Username'];
    header('location: adminpage.php');
}
elseif (password_verify($_POST['Password'], $user)) {
    $_SESSION['loggedin'] = true;
    $_SESSION['username'] = $_POST['Username'];
    header('location: latestarticles.php');
    } else {
        echo '
 Wrong password
';
    }
}

I want this code to check if the $admin variable has a value or not, if it does then you get admin rights if not then you get normal user rights. But the $admin = $stmt->fetchColumn(6); doesn't show any results.

UPDATE: One thing that I have just tried was adding another search query beneath the first fetchColumn, it works but surely this can't be the only way, there has to be something easier.
My code looks like this now:

$stmt = $pdo->prepare('SELECT * FROM logins WHERE login_name = :username');
$criteria = ['username' => $_POST['Username']];
$stmt->execute($criteria);
$user = $stmt->fetchColumn(1);
$stmt = $pdo->prepare('SELECT * FROM logins WHERE login_name = :username');
$criteria = ['username' => $_POST['Username']];
$stmt->execute($criteria);
$admin = $stmt->fetchColumn(6);
if (password_verify($_POST['Password'], $user) && !empty($admin)) {
    $_SESSION['adminlogin'] = true;
    $_SESSION['loggedin'] = true;
    $_SESSION['adminloginname'] = $_POST['Username'];
    header('location: adminpage.php');
}
 elseif (password_verify($_POST['Password'], $user)) {
    $_SESSION['loggedin'] = true;
    $_SESSION['username'] = $_POST['Username'];
    header('location: latestarticles.php');
    } else {
        echo '
 Wrong password
';
    }

Body:
php manual says:

(1) fetchColumn() should not be used to retrieve boolean columns, as it is
  impossible to distinguish a value of FALSE from there being no more
  rows to retrieve

(2) There is no way to return another column from the same row if
  you use PDOStatement::fetchColumn() to retrieve data.

Instead you could do this with fetch() method as shown below:

$result = $stmt->fetch(PDO::FETCH_ASSOC);
$user = $result['user_column'];
$admin = $result['admin_column'];

Here is the PHP manual reference: http://php.net/manual/en/pdostatement.fetch.php


问:
Replace values of multiple columns from one dataframe using another dataframe with conditions
Hi I have two data frames as followed:

```<code>df1:
ID   x    y     z
1    a    b     c
2    a    b     c
3    a    b     c
4    a    b     c
</code>```

and df2:

```<code>ID   x    y
 2   d    NA
 3   NA   e
</code>```

and I am after a result like this:

df1:

```<code>    ID   x    y     z
    1    a    b     c
    2    d    b     c
    3    a    e     c
    4    a    b     c
</code>```

I have been trying to use the match function as suggested by some other posts but I keep getting the issue where my df1 dataframe being replaced with NA values from df2.
This is the code I have been using without luck

```<code>for (i in names(df2)[2:length(names(df2))]) {
  df1[i] <- df2[match(df1$ID, df2$ID)]
}
</code>```

Thanks

答:
A solution using dplyr. The idea is to convert both data frames to long format, conduct join and replace the values, and convert the format back to wide format. df5 is the final output.

```<code>library(dplyr)
library(tidyr)

df3 <- df1 %>% gather(Col, Value, -ID)
df4 <- df2 %>% gather(Col, Value, -ID, na.rm = TRUE)
df5 <- df3 %>%
  left_join(df4, by = c("ID", "Col")) %>%
  mutate(Value.x = ifelse(!is.na(Value.y), Value.y, Value.x)) %>%
  select(ID, Col, Value.x) %>%
  spread(Col, Value.x)
df5
#   ID x y z
# 1  1 a b c
# 2  2 d b c
# 3  3 a e c
# 4  4 a b c
</code>```

DATA

```<code>df1 <- read.table(text = "ID   x    y     z
1    a    b     c
                  2    a    b     c
                  3    a    b     c
                  4    a    b     c",
                  header = TRUE, stringsAsFactors = FALSE)

df2 <- read.table(text = "ID   x    y
 2   d    NA
 3   NA   e",
                  header = TRUE, stringsAsFactors = FALSE)
</code>```

Body:
Hi I have two data frames as followed:

df1:
ID   x    y     z
1    a    b     c
2    a    b     c
3    a    b     c
4    a    b     c

and df2:

ID   x    y
 2   d    NA
 3   NA   e

and I am after a result like this:

df1:

    ID   x    y     z
    1    a    b     c
    2    d    b     c
    3    a    e     c
    4    a    b     c

I have been trying to use the match function as suggested by some other posts but I keep getting the issue where my df1 dataframe being replaced with NA values from df2.
This is the code I have been using without luck

for (i in names(df2)[2:length(names(df2))]) {
  df1[i] <- df2[match(df1$ID, df2$ID)]
}

Thanks

Body:
A solution using dplyr. The idea is to convert both data frames to long format, conduct join and replace the values, and convert the format back to wide format. df5 is the final output.

library(dplyr)
library(tidyr)

df3 <- df1 %>% gather(Col, Value, -ID)
df4 <- df2 %>% gather(Col, Value, -ID, na.rm = TRUE)
df5 <- df3 %>%
  left_join(df4, by = c("ID", "Col")) %>%
  mutate(Value.x = ifelse(!is.na(Value.y), Value.y, Value.x)) %>%
  select(ID, Col, Value.x) %>%
  spread(Col, Value.x)
df5
#   ID x y z
# 1  1 a b c
# 2  2 d b c
# 3  3 a e c
# 4  4 a b c

DATA

df1 <- read.table(text = "ID   x    y     z
1    a    b     c
                  2    a    b     c
                  3    a    b     c
                  4    a    b     c",
                  header = TRUE, stringsAsFactors = FALSE)

df2 <- read.table(text = "ID   x    y
 2   d    NA
 3   NA   e",
                  header = TRUE, stringsAsFactors = FALSE)


问:
Hooking API Calls in Current Process?
How do I go about hooking/redirecting a function in a DLL (say, CreateThread from Kernel32.dll) loaded in the current process?

(I don't have control over which pieces of code call CreateThread, so it's not like I can just have the code something else instead.)

The language doesn't matter much; I'm guessing C/C++ would be the best choices for this.

Update:

I forgot to mention: I'm not looking for solutions that require the bundling of extra libraries into my program; I was looking for a manual way of doing the hooking (such as by rewriting the address of the function), not for using an external library to do this.

But thanks to those who mentioned an external library; sorry I didn't say this earlier.

答:
(This most likely would have been more appropriate as a "comment" under the "Detours" answer, but, as my "reputation" isn't enough yet to add comments I guess, let me post it as an answer)

This post under this thread ("DirectShow question") mentions a replacement/home-grown alternative to Detours (with some rough code example as well) by Alessandro Angeli.

I've actually first found it quoted in another thread ("problem in hooking cocreateinstance") while also searching for COM component creation hooking/tracing (This second thread is more focused on cross-process hooking though).

Let me also add a link for WinAPIOverride32 (by Jacquelin Potier) for convenience here as well. It seems to have "developer designed GUI" :) but, no complaints at all as it is open source (as mentioned above).

ContentLicense: CC BY-SA 2.5

Title: Hooking API Calls in Current Process?


问:
Split hive partition to create multiple partition
I have an external hive table which is partitioned on load_date (DD-MM-YYYY). however the very first period lets say 01-01-2000 has all the data from 1980 till 2000. How can I further create partitions on year for the previous data while keeping the existing data (data for load date greater than 01-01-2000) still available</p>

答: First load the data of '01-01-2000' into a table and create a dynamic partition table partitioned by data '01-01-2000'. This might solve your problem.</p>


问:
Make waveform like Soundcoud Player with javascript/jQuery in html5
I want to make a audio player look like Soundcloud player with waveform made from mp3 file using javascript/jQuery and html5 canvas. I know that there is a lot of questions like mine on stackoverflow but no one can find a true answer...

I made this but it's not really nice.

        var imgBg = new Image(),
            imgFg = new Image(),
            count = 2;
        imgBg.onload = imgFg.onload = init;
        imgBg.src = "http://www.filetolink.com/605b7afaa1";
        imgFg.src = "https://files.fm/thumb_show.php?i=5ddxxmmn";

        function init() {
          if (--count) return;   // makes sure both images are loaded

           var canvas = document.querySelector("canvas"),
               ctx = canvas.getContext("2d"),
               audio =  document.querySelector("audio");

          canvas.width = imgBg.naturalWidth;
          canvas.height = imgBg.naturalHeight;

          render();

          audio.volume = 0.5;
          audio.addEventListener("timeupdate", render);

          function render() {
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            ctx.drawImage(imgBg, 0, 0);

            // calc progress
            var pst = audio.currentTime / audio.duration;

            // draw clipped version of top image
            if (pst > 0) {
              ctx.drawImage(imgFg, 0, 0, (canvas.width * pst)|0, canvas.height,  // source
                                   0, 0, (canvas.width * pst)|0, canvas.height); // dst
            }
          }
        }```
<pre class="snippet-code-css lang-css prettyprint-override"><code>        body {background:#ccc}
        canvas {width:600px;height:auto; background:#CCCCCC}</code>```

  <audio src="https://failiem.lv/down.php?i=puupmmqb" controls=""></audio>
  <canvas height="238" width="1470"></canvas>```

I already found lot of script arround the web but no one look like soundcloud player.

List of links that i found on the web but not exactly like i'm searching for :

https://github.com/AlexJuca/SpectrumVisualizer

https://github.com/michaeldzjap/waveplayer.js?files=1

https://github.com/katspaugh/wavesurfer.js

Thank to everyone who can help me and thank you for your advices.

答:
If you want to do like soundcloud, don't forget that no matter how difficult it is you will just look like a copy.
Separate the two parts.
Build that player using waveform.
Secondly make you cursor look like a pointer, and wherever you clik you hook the fact that you can post a comment based on the percentage you are in the song.
Sorry as i'm french but thinking like this i think you are going to understand easier what you have to do !

Look at this : http://preview.codecanyon.net/item/audio-waveform-player-with-playlist/full_screen_preview/18420897?_ga=2.157064376.2056415136.1512709641-883454457.1511933135

Body:
I want to make a audio player look like Soundcloud player with waveform made from mp3 file using javascript/jQuery and html5 canvas. I know that there is a lot of questions like mine on stackoverflow but no one can find a true answer...

I made this but it's not really nice.

        var imgBg = new Image(),
            imgFg = new Image(),
            count = 2;
        imgBg.onload = imgFg.onload = init;
        imgBg.src = "http://www.filetolink.com/605b7afaa1";
        imgFg.src = "https://files.fm/thumb_show.php?i=5ddxxmmn";

        function init() {
          if (--count) return;   // makes sure both images are loaded

           var canvas = document.querySelector("canvas"),
               ctx = canvas.getContext("2d"),
               audio =  document.querySelector("audio");

          canvas.width = imgBg.naturalWidth;
          canvas.height = imgBg.naturalHeight;

          render();

          audio.volume = 0.5;
          audio.addEventListener("timeupdate", render);

          function render() {
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            ctx.drawImage(imgBg, 0, 0);

            // calc progress
            var pst = audio.currentTime / audio.duration;

            // draw clipped version of top image
            if (pst > 0) {
              ctx.drawImage(imgFg, 0, 0, (canvas.width * pst)|0, canvas.height,  // source
                                   0, 0, (canvas.width * pst)|0, canvas.height); // dst
            }
          }
        }

        body {background:#ccc}
        canvas {width:600px;height:auto; background:#CCCCCC}

  <audio src="https://failiem.lv/down.php?i=puupmmqb" controls=""></audio>
  <canvas height="238" width="1470"></canvas>

I already found lot of script arround the web but no one look like soundcloud player.

List of links that i found on the web but not exactly like i'm searching for :

https://github.com/AlexJuca/SpectrumVisualizer

https://github.com/michaeldzjap/waveplayer.js?files=1

https://github.com/katspaugh/wavesurfer.js

Thank to everyone who can help me and thank you for your advices.


问:
Grunt Task in Release Manager: Default not found
I cannot get a simple Grunt task to work in release manager. I keep getting Warning: Task "default" not found. Used --force, continuing.  I added --force to keep the build from failing but the grunt task is not processing.  I have logged into the build agent and run grunt manually with no problems.

Any help or ideas would be greatly appreciated.

Thanks,

module.exports = function (grunt) {
    'use strict';

```<code>grunt.initConfig({

    //Read the package.json (optional)
    pkg: grunt.file.readJSON('package.json'),

    // Cache bust css, update AppInsights key, remove all custom js imports from index.html, https url rewrites
    processhtml: {
        dev: {
            options: {
                data: {
                    appInsightsKey: 'f8d00249-dd60-44be-9145-dcb303e5fd19',
                    timestamp: Date.now()
                }
            },
            files:
            {
                'wwwroot/index2.html': ['wwwroot/index.html']
            }
        },
    },
    // Combine and minify all js in /app folder and subfolders into app.min.js
    uglify: {
        dev: {
            src: ['wwwroot/app/app.module.js', 'wwwroot/app/**/*.module.js', 'wwwroot/app/core/*.js', 'wwwroot/app/services/*.js', 'wwwroot/app/layout/*.js', 'wwwroot/app/**/*.js'],
            dest: 'wwwroot/app/app1.min.js'
        }
    },
    // Delete all js except for app.min.js in /app folder and subfolders
    clean: {
        dev: {
            options: {
                force: true
            },
            expand: true,
            src: ['app/**/*.js', '!app/app.min.js']
        }
    }
});

grunt.loadNpmTasks('grunt-processhtml');
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask("default", "watch");

// If no target provided, default to dev
var target = grunt.option('target') || 'dev';
//grunt.registerTask('default', ['processhtml:' + target, 'uglify:' + target, 'clean:' + target]);
grunt.registerTask('default', ['processhtml:' + target, 'uglify:' + target]);
</code>```

};

Grunt Task

答: Based on the screenshot, you specified the package.json as grunt file, by default, the file is the js file (e.g. Gruntfile.js), so check whether you specified the correct file.

Body:
I cannot get a simple Grunt task to work in release manager. I keep getting Warning: Task "default" not found. Used --force, continuing.  I added --force to keep the build from failing but the grunt task is not processing.  I have logged into the build agent and run grunt manually with no problems.

Any help or ideas would be greatly appreciated.

Thanks,

module.exports = function (grunt) {
    'use strict';

grunt.initConfig({

    //Read the package.json (optional)
    pkg: grunt.file.readJSON('package.json'),

    // Cache bust css, update AppInsights key, remove all custom js imports from index.html, https url rewrites
    processhtml: {
        dev: {
            options: {
                data: {
                    appInsightsKey: 'f8d00249-dd60-44be-9145-dcb303e5fd19',
                    timestamp: Date.now()
                }
            },
            files:
            {
                'wwwroot/index2.html': ['wwwroot/index.html']
            }
        },
    },
    // Combine and minify all js in /app folder and subfolders into app.min.js
    uglify: {
        dev: {
            src: ['wwwroot/app/app.module.js', 'wwwroot/app/**/*.module.js', 'wwwroot/app/core/*.js', 'wwwroot/app/services/*.js', 'wwwroot/app/layout/*.js', 'wwwroot/app/**/*.js'],
            dest: 'wwwroot/app/app1.min.js'
        }
    },
    // Delete all js except for app.min.js in /app folder and subfolders
    clean: {
        dev: {
            options: {
                force: true
            },
            expand: true,
            src: ['app/**/*.js', '!app/app.min.js']
        }
    }
});

grunt.loadNpmTasks('grunt-processhtml');
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask("default", "watch");

// If no target provided, default to dev
var target = grunt.option('target') || 'dev';
//grunt.registerTask('default', ['processhtml:' + target, 'uglify:' + target, 'clean:' + target]);
grunt.registerTask('default', ['processhtml:' + target, 'uglify:' + target]);

};

Grunt Task


问:
Elixir: Run function after another function
I'm still quite new to Elixir and checking out some code in a repository and wondering if there is a way to cut down the following code snippet:

```<code>  def find(client) do
    Common.find(client, @resource)
    |> ResponseHandler.handle_response(@model_module)
  end

  def find(client, identifier) do
    Common.find(client, @resource, identifier)
    |> ResponseHandler.handle_response(@model_module)
  end

  def filter(client, filter) do
    Common.filter(client, @resource, filter)
    |> ResponseHandler.handle_response(@model_module)
  end

  def create(client, bank_transactions_map) do
    Common.create(client, @resource, bank_transactions_map)
    |> ResponseHandler.handle_response(@model_module)
  end

  def update(client, identifier, bank_transactions_map) do
    Common.update(client, @resource, identifier, bank_transactions_map)
    |> ResponseHandler.handle_response(@model_module)
  end
</code>```

All the functions here pipe into the same function and it seems a little repetitive. Is there a way to set up a function in the module to take in an argument and run the .handle_response line without setting it in each function here?

答:
If that is the real codepiece, meaning the functions are wrappers for the functions from another module having the same names and interspersed with @resource parameter list, one might define them dynamically:

functions =
  [find: ~w|client|a,
   find: ~w|client identifier|a,
   filter: ~w|client filter|a,
   create: ~w|client bank_transactions_map|a,
   update: ~w|client identifier bank_transactions_map|a]

Enum.each(functions, fn {fun, args} ->
  args = Enum.map args, &{&1, [], Elixir}
  wrapped_args = with [h | t] <- args,
    do: [h | [ quote(do: @resource) | t ]] # inject @resource
  def unquote(fun)(unquote_splicing(args)) do
    Common
    |> apply(unquote(fun), unquote(wrapped_args))
    |> ResponseHandler.handle_response(@model_module)
  end
end)
```

If the wrapping is not as pure, the initial list of functions to wrap should be extended to something like [find: [params: [...], as: :search].

The advantage of this approach is that once the function producer is written and well-tested, adding the new wrappers is as easy as updating a config file.

Body:
I'm still quite new to Elixir and checking out some code in a repository and wondering if there is a way to cut down the following code snippet:

  def find(client) do
    Common.find(client, @resource)
    |> ResponseHandler.handle_response(@model_module)
  end

  def find(client, identifier) do
    Common.find(client, @resource, identifier)
    |> ResponseHandler.handle_response(@model_module)
  end

  def filter(client, filter) do
    Common.filter(client, @resource, filter)
    |> ResponseHandler.handle_response(@model_module)
  end

  def create(client, bank_transactions_map) do
    Common.create(client, @resource, bank_transactions_map)
    |> ResponseHandler.handle_response(@model_module)
  end

  def update(client, identifier, bank_transactions_map) do
    Common.update(client, @resource, identifier, bank_transactions_map)
    |> ResponseHandler.handle_response(@model_module)
  end

All the functions here pipe into the same function and it seems a little repetitive. Is there a way to set up a function in the module to take in an argument and run the .handle_response line without setting it in each function here?

Body:
If that is the real codepiece, meaning the functions are wrappers for the functions from another module having the same names and interspersed with @resource parameter list, one might define them dynamically:

functions =
  [find: ~w|client|a,
   find: ~w|client identifier|a,
   filter: ~w|client filter|a,
   create: ~w|client bank_transactions_map|a,
   update: ~w|client identifier bank_transactions_map|a]

Enum.each(functions, fn {fun, args} ->
  args = Enum.map args, &{&1, [], Elixir}
  wrapped_args = with [h | t] <- args,
    do: [h | [ quote(do: @resource) | t ]] # inject @resource
  def unquote(fun)(unquote_splicing(args)) do
    Common
    |> apply(unquote(fun), unquote(wrapped_args))
    |> ResponseHandler.handle_response(@model_module)
  end
end)

If the wrapping is not as pure, the initial list of functions to wrap should be extended to something like [find: [params: [...], as: :search].

The advantage of this approach is that once the function producer is written and well-tested, adding the new wrappers is as easy as updating a config file.